package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.QualFilingMaterialEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.QualFilingMaterialGateway;
import org.qinan.safetyeval.domain.query.QualFilingMaterialQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

/**
 * 备案申请材料领域服务
 *
 * @author safety-eval
 */
@Service
public class QualFilingMaterialDomainService {

    @Resource
    private QualFilingMaterialGateway qualFilingMaterialGateway;

    public QualFilingMaterialEntity add(QualFilingMaterialEntity entity) {
        return qualFilingMaterialGateway.save(entity);
    }

    public QualFilingMaterialEntity get(Long id) {
        return qualFilingMaterialGateway.get(id);
    }

    public QualFilingMaterialEntity modify(QualFilingMaterialEntity entity) {
        QualFilingMaterialEntity existing = qualFilingMaterialGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_MATERIAL_NOT_FOUND);
        }
        return qualFilingMaterialGateway.modify(entity);
    }

    public void delete(Long id) {
        QualFilingMaterialEntity existing = qualFilingMaterialGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_MATERIAL_NOT_FOUND);
        }
        qualFilingMaterialGateway.delete(id);
    }

    public PageResult<QualFilingMaterialEntity> page(QualFilingMaterialQuery query) {
        return qualFilingMaterialGateway.page(query);
    }
}
