package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.QualFilingChangeEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.QualFilingChangeGateway;
import org.qinan.safetyeval.domain.query.QualFilingChangeQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

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

    @Resource
    private QualFilingChangeGateway qualFilingChangeGateway;

    public QualFilingChangeEntity add(QualFilingChangeEntity entity) {
        return qualFilingChangeGateway.save(entity);
    }

    public QualFilingChangeEntity get(Long id) {
        return qualFilingChangeGateway.get(id);
    }

    public QualFilingChangeEntity modify(QualFilingChangeEntity entity) {
        QualFilingChangeEntity existing = qualFilingChangeGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_CHANGE_NOT_FOUND);
        }
        return qualFilingChangeGateway.modify(entity);
    }

    public void delete(Long id) {
        QualFilingChangeEntity existing = qualFilingChangeGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_CHANGE_NOT_FOUND);
        }
        qualFilingChangeGateway.delete(id);
    }

    public PageResult<QualFilingChangeEntity> page(QualFilingChangeQuery query) {
        return qualFilingChangeGateway.page(query);
    }
}
