package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.QualFilingPersonnelEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.QualFilingPersonnelGateway;
import org.qinan.safetyeval.domain.query.QualFilingPersonnelQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

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

    @Resource
    private QualFilingPersonnelGateway qualFilingPersonnelGateway;

    public QualFilingPersonnelEntity add(QualFilingPersonnelEntity entity) {
        return qualFilingPersonnelGateway.save(entity);
    }

    public QualFilingPersonnelEntity get(Long id) {
        return qualFilingPersonnelGateway.get(id);
    }

    public QualFilingPersonnelEntity modify(QualFilingPersonnelEntity entity) {
        QualFilingPersonnelEntity existing = qualFilingPersonnelGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_PERSONNEL_NOT_FOUND);
        }
        return qualFilingPersonnelGateway.modify(entity);
    }

    public void delete(Long id) {
        QualFilingPersonnelEntity existing = qualFilingPersonnelGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_PERSONNEL_NOT_FOUND);
        }
        qualFilingPersonnelGateway.delete(id);
    }

    public PageResult<QualFilingPersonnelEntity> page(QualFilingPersonnelQuery query) {
        return qualFilingPersonnelGateway.page(query);
    }
}
