package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.QualFilingChangeDetailEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.QualFilingChangeDetailGateway;
import org.qinan.safetyeval.domain.query.QualFilingChangeDetailQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

/**
 * 备案变更明细领域服务
 *
 * @author safety-eval
 */
@Service
public class QualFilingChangeDetailDomainService {

    @Resource
    private QualFilingChangeDetailGateway qualFilingChangeDetailGateway;

    public QualFilingChangeDetailEntity add(QualFilingChangeDetailEntity entity) {
        return qualFilingChangeDetailGateway.save(entity);
    }

    public QualFilingChangeDetailEntity get(Long id) {
        return qualFilingChangeDetailGateway.get(id);
    }

    public QualFilingChangeDetailEntity modify(QualFilingChangeDetailEntity entity) {
        QualFilingChangeDetailEntity existing = qualFilingChangeDetailGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_CHANGE_DETAIL_NOT_FOUND);
        }
        return qualFilingChangeDetailGateway.modify(entity);
    }

    public void delete(Long id) {
        QualFilingChangeDetailEntity existing = qualFilingChangeDetailGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_CHANGE_DETAIL_NOT_FOUND);
        }
        qualFilingChangeDetailGateway.delete(id);
    }

    public PageResult<QualFilingChangeDetailEntity> page(QualFilingChangeDetailQuery query) {
        return qualFilingChangeDetailGateway.page(query);
    }
}
