package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.OrgPersonnelCertEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.OrgPersonnelCertGateway;
import org.qinan.safetyeval.domain.query.OrgPersonnelCertQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

/**
 * 人员证书领域服务
 *
 * @author safety-eval
 */
@Service
public class OrgPersonnelCertDomainService {

    @Resource
    private OrgPersonnelCertGateway orgPersonnelCertGateway;

    public OrgPersonnelCertEntity add(OrgPersonnelCertEntity entity) {
        return orgPersonnelCertGateway.save(entity);
    }

    public OrgPersonnelCertEntity get(Long id) {
        return orgPersonnelCertGateway.get(id);
    }

    public OrgPersonnelCertEntity modify(OrgPersonnelCertEntity entity) {
        OrgPersonnelCertEntity existing = orgPersonnelCertGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_PERSONNEL_CERT_NOT_FOUND);
        }
        return orgPersonnelCertGateway.modify(entity);
    }

    public void delete(Long id) {
        OrgPersonnelCertEntity existing = orgPersonnelCertGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_PERSONNEL_CERT_NOT_FOUND);
        }
        orgPersonnelCertGateway.delete(id);
    }

    public PageResult<OrgPersonnelCertEntity> page(OrgPersonnelCertQuery query) {
        return orgPersonnelCertGateway.page(query);
    }
}
