package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.OrgPositionEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.OrgPositionGateway;
import org.qinan.safetyeval.domain.query.OrgPositionQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

/**
 * 岗位领域服务
 *
 * @author safety-eval
 */
@Service
public class OrgPositionDomainService {

    @Resource
    private OrgPositionGateway orgPositionGateway;

    public OrgPositionEntity add(OrgPositionEntity entity) {
        return orgPositionGateway.save(entity);
    }

    public OrgPositionEntity get(Long id) {
        return orgPositionGateway.get(id);
    }

    public OrgPositionEntity modify(OrgPositionEntity entity) {
        OrgPositionEntity existing = orgPositionGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_POSITION_NOT_FOUND);
        }
        return orgPositionGateway.modify(entity);
    }

    public void delete(Long id) {
        OrgPositionEntity existing = orgPositionGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_POSITION_NOT_FOUND);
        }
        orgPositionGateway.delete(id);
    }

    public PageResult<OrgPositionEntity> page(OrgPositionQuery query) {
        return orgPositionGateway.page(query);
    }
}
