package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.OrgPersonnelChangeEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.OrgPersonnelChangeGateway;
import org.qinan.safetyeval.domain.query.OrgPersonnelChangeQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

/**
 * 人员变更记录领域服务
 *
 * @author safety-eval
 */
@Service
public class OrgPersonnelChangeDomainService {

    @Resource
    private OrgPersonnelChangeGateway orgPersonnelChangeGateway;

    public OrgPersonnelChangeEntity add(OrgPersonnelChangeEntity entity) {
        return orgPersonnelChangeGateway.save(entity);
    }

    public OrgPersonnelChangeEntity get(Long id) {
        return orgPersonnelChangeGateway.get(id);
    }

    public OrgPersonnelChangeEntity modify(OrgPersonnelChangeEntity entity) {
        OrgPersonnelChangeEntity existing = orgPersonnelChangeGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_PERSONNEL_CHANGE_NOT_FOUND);
        }
        return orgPersonnelChangeGateway.modify(entity);
    }

    public void delete(Long id) {
        OrgPersonnelChangeEntity existing = orgPersonnelChangeGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_PERSONNEL_CHANGE_NOT_FOUND);
        }
        orgPersonnelChangeGateway.delete(id);
    }

    public PageResult<OrgPersonnelChangeEntity> page(OrgPersonnelChangeQuery query) {
        return orgPersonnelChangeGateway.page(query);
    }
}
