package com.tashow.cloud.product.service.impl;

import com.tashow.cloud.productapi.api.product.dto.ProdEmergencyResponseDO;
import com.tashow.cloud.product.mapper.ProdEmergencyResponseMapper;
import com.tashow.cloud.product.service.ProdEmergencyResponseService;
import com.tashow.cloud.productapi.api.product.vo.prodemergencyresponse.ProdEmergencyResponsePageReqVO;
import com.tashow.cloud.productapi.api.product.vo.prodemergencyresponse.ProdEmergencyResponseSaveReqVO;
import com.tashow.cloud.productapi.enums.ErrorCodeConstants;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.tashow.cloud.common.pojo.PageResult;
import com.tashow.cloud.common.pojo.PageParam;
import com.tashow.cloud.common.util.object.BeanUtils;


import static com.tashow.cloud.common.exception.util.ServiceExceptionUtil.exception;

/**
 * 商品紧急响应服务设置 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class ProdEmergencyResponseServiceImpl implements ProdEmergencyResponseService {

    @Resource
    private ProdEmergencyResponseMapper prodEmergencyResponseMapper;

    @Override
    public Long createProdEmergencyResponse(ProdEmergencyResponseSaveReqVO createReqVO) {
        // 插入
        ProdEmergencyResponseDO prodEmergencyResponse = BeanUtils.toBean(createReqVO, ProdEmergencyResponseDO.class);
        prodEmergencyResponseMapper.insert(prodEmergencyResponse);
        // 返回
        return prodEmergencyResponse.getId();
    }

    @Override
    public void updateProdEmergencyResponse(ProdEmergencyResponseSaveReqVO updateReqVO) {
        // 校验存在
        validateProdEmergencyResponseExists(updateReqVO.getId());
        // 更新
        ProdEmergencyResponseDO updateObj = BeanUtils.toBean(updateReqVO, ProdEmergencyResponseDO.class);
        prodEmergencyResponseMapper.updateById(updateObj);
    }

    @Override
    public void deleteProdEmergencyResponse(Long id) {
        // 校验存在
        validateProdEmergencyResponseExists(id);
        // 删除
        prodEmergencyResponseMapper.deleteById(id);
    }

    private void validateProdEmergencyResponseExists(Long id) {
        if (prodEmergencyResponseMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.PROD_EMERGENCY_RESPONSE_NOT_EXISTS);
        }
    }

    @Override
    public ProdEmergencyResponseDO getProdEmergencyResponse(Long id) {
        return prodEmergencyResponseMapper.selectById(id);
    }

    @Override
    public PageResult<ProdEmergencyResponseDO> getProdEmergencyResponsePage(ProdEmergencyResponsePageReqVO pageReqVO) {
        return null;
    }

}