package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.QualFilingCommitmentEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.QualFilingCommitmentGateway;
import org.qinan.safetyeval.domain.query.QualFilingCommitmentQuery;
import org.qinan.safetyeval.domain.query.PageResult;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 法定代表人承诺书领域服务
 *
 * @author safety-eval
 */
@Service
public class QualFilingCommitmentDomainService {

    @Resource
    private QualFilingCommitmentGateway qualFilingCommitmentGateway;

    public QualFilingCommitmentEntity add(QualFilingCommitmentEntity entity) {
        return qualFilingCommitmentGateway.save(entity);
    }

    public QualFilingCommitmentEntity get(Long id) {
        return qualFilingCommitmentGateway.get(id);
    }

    public QualFilingCommitmentEntity modify(QualFilingCommitmentEntity entity) {
        QualFilingCommitmentEntity existing = qualFilingCommitmentGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_COMMITMENT_NOT_FOUND);
        }
        return qualFilingCommitmentGateway.modify(entity);
    }

    public void delete(Long id) {
        QualFilingCommitmentEntity existing = qualFilingCommitmentGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_COMMITMENT_NOT_FOUND);
        }
        qualFilingCommitmentGateway.delete(id);
    }

    public PageResult<QualFilingCommitmentEntity> page(QualFilingCommitmentQuery query) {
        return qualFilingCommitmentGateway.page(query);
    }
}
