package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.QualFilingPersonnelCertEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.QualFilingPersonnelCertGateway;
import org.qinan.safetyeval.domain.query.QualFilingPersonnelCertQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

/**
 * 备案申请人员证书领域服务
 *
 * @author safety-eval
 */
@Service
public class QualFilingPersonnelCertDomainService {

    @Resource
    private QualFilingPersonnelCertGateway qualFilingPersonnelCertGateway;

    public QualFilingPersonnelCertEntity add(QualFilingPersonnelCertEntity entity) {
        return qualFilingPersonnelCertGateway.save(entity);
    }

    public QualFilingPersonnelCertEntity get(Long id) {
        return qualFilingPersonnelCertGateway.get(id);
    }

    public QualFilingPersonnelCertEntity modify(QualFilingPersonnelCertEntity entity) {
        QualFilingPersonnelCertEntity existing = qualFilingPersonnelCertGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_PERSONNEL_CERT_NOT_FOUND);
        }
        return qualFilingPersonnelCertGateway.modify(entity);
    }

    public void delete(Long id) {
        QualFilingPersonnelCertEntity existing = qualFilingPersonnelCertGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_PERSONNEL_CERT_NOT_FOUND);
        }
        qualFilingPersonnelCertGateway.delete(id);
    }

    public PageResult<QualFilingPersonnelCertEntity> page(QualFilingPersonnelCertQuery query) {
        return qualFilingPersonnelCertGateway.page(query);
    }
}
