package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.QualFilingEquipmentEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.QualFilingEquipmentGateway;
import org.qinan.safetyeval.domain.query.QualFilingEquipmentQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

/**
 * 备案申请装备领域服务
 *
 * @author safety-eval
 */
@Service
public class QualFilingEquipmentDomainService {

    @Resource
    private QualFilingEquipmentGateway qualFilingEquipmentGateway;

    public QualFilingEquipmentEntity add(QualFilingEquipmentEntity entity) {
        return qualFilingEquipmentGateway.save(entity);
    }

    public QualFilingEquipmentEntity get(Long id) {
        return qualFilingEquipmentGateway.get(id);
    }

    public QualFilingEquipmentEntity modify(QualFilingEquipmentEntity entity) {
        QualFilingEquipmentEntity existing = qualFilingEquipmentGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_EQUIPMENT_NOT_FOUND);
        }
        return qualFilingEquipmentGateway.modify(entity);
    }

    public void delete(Long id) {
        QualFilingEquipmentEntity existing = qualFilingEquipmentGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.QUAL_FILING_EQUIPMENT_NOT_FOUND);
        }
        qualFilingEquipmentGateway.delete(id);
    }

    public PageResult<QualFilingEquipmentEntity> page(QualFilingEquipmentQuery query) {
        return qualFilingEquipmentGateway.page(query);
    }
}
