package org.qinan.safetyeval.domain.service;

import org.qinan.safetyeval.domain.entity.OrgEquipmentEntity;
import org.qinan.safetyeval.domain.exception.BizException;
import org.qinan.safetyeval.domain.exception.ErrorCode;
import org.qinan.safetyeval.domain.gateway.OrgEquipmentGateway;
import org.qinan.safetyeval.domain.query.OrgEquipmentQuery;
import org.qinan.safetyeval.domain.query.PageResult;

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

/**
 * 装备信息领域服务
 *
 * @author safety-eval
 */
@Service
public class OrgEquipmentDomainService {

    @Resource
    private OrgEquipmentGateway orgEquipmentGateway;

    public OrgEquipmentEntity add(OrgEquipmentEntity entity) {
        return orgEquipmentGateway.save(entity);
    }

    public OrgEquipmentEntity get(Long id) {
        return orgEquipmentGateway.get(id);
    }

    public OrgEquipmentEntity modify(OrgEquipmentEntity entity) {
        OrgEquipmentEntity existing = orgEquipmentGateway.get(entity.getId());
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_EQUIPMENT_NOT_FOUND);
        }
        return orgEquipmentGateway.modify(entity);
    }

    public void delete(Long id) {
        OrgEquipmentEntity existing = orgEquipmentGateway.get(id);
        if (existing == null) {
            throw new BizException(ErrorCode.ORG_EQUIPMENT_NOT_FOUND);
        }
        orgEquipmentGateway.delete(id);
    }

    public PageResult<OrgEquipmentEntity> page(OrgEquipmentQuery query) {
        return orgEquipmentGateway.page(query);
    }
}
