package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.OrgQualificationEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.OrgQualificationGateway;
import org.qinan.safetyeval.domain.query.OrgQualificationQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

import java.util.List;

/**
 * 机构资质证书领域服务
 *
 * @author safety-eval
 */
@Service
public class OrgQualificationDomainService {

    @Resource
    private OrgQualificationGateway orgQualificationGateway;

    public OrgQualificationEntity add(OrgQualificationEntity entity) {
        return orgQualificationGateway.save(entity);
    }

    public OrgQualificationEntity get(Long id) {
        return orgQualificationGateway.get(id);
    }

    public OrgQualificationEntity modify(OrgQualificationEntity entity) {
        OrgQualificationEntity existing = orgQualificationGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_QUALIFICATION_NOT_FOUND);
        }
        return orgQualificationGateway.modify(entity);
    }

    public void delete(Long id) {
        OrgQualificationEntity existing = orgQualificationGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_QUALIFICATION_NOT_FOUND);
        }
        orgQualificationGateway.delete(id);
    }

    public PageResult<OrgQualificationEntity> page(OrgQualificationQuery query) {
        return orgQualificationGateway.page(query);
    }

    public List<OrgQualificationEntity> classGet(Long id) {
        return orgQualificationGateway.classGet(id);
    }
}
