package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.OrgResignApplyEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.OrgResignApplyGateway;
import org.qinan.safetyeval.domain.query.OrgResignApplyQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

/**
 * 人员离职申请领域服务
 *
 * @author safety-eval
 */
@Service
public class OrgResignApplyDomainService {

    @Resource
    private OrgResignApplyGateway orgResignApplyGateway;

    public OrgResignApplyEntity add(OrgResignApplyEntity entity) {
        return orgResignApplyGateway.save(entity);
    }

    public OrgResignApplyEntity get(Long id) {
        return orgResignApplyGateway.get(id);
    }

    public OrgResignApplyEntity modify(OrgResignApplyEntity entity) {
        OrgResignApplyEntity existing = orgResignApplyGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_RESIGN_APPLY_NOT_FOUND);
        }
        return orgResignApplyGateway.modify(entity);
    }

    public void delete(Long id) {
        OrgResignApplyEntity existing = orgResignApplyGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_RESIGN_APPLY_NOT_FOUND);
        }
        orgResignApplyGateway.delete(id);
    }

    public PageResult<OrgResignApplyEntity> page(OrgResignApplyQuery query) {
        return orgResignApplyGateway.page(query);
    }
}
