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

import com.tashow.cloud.productapi.api.product.dto.ProdServiceOverAreaRulesDO;
import com.tashow.cloud.product.mapper.ProdServiceOverAreaRulesMapper;
import com.tashow.cloud.product.service.ProdServiceOverAreaRulesService;
import com.tashow.cloud.productapi.api.product.vo.prodserviceoverarearules.ProdServiceOverAreaRulesPageReqVO;
import com.tashow.cloud.productapi.api.product.vo.prodserviceoverarearules.ProdServiceOverAreaRulesSaveReqVO;
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 ProdServiceOverAreaRulesServiceImpl implements ProdServiceOverAreaRulesService {

    @Resource
    private ProdServiceOverAreaRulesMapper prodServiceOverAreaRulesMapper;

    @Override
    public Long createProdServiceOverAreaRules(ProdServiceOverAreaRulesSaveReqVO createReqVO) {
        // 插入
        ProdServiceOverAreaRulesDO prodServiceOverAreaRules = BeanUtils.toBean(createReqVO, ProdServiceOverAreaRulesDO.class);
        prodServiceOverAreaRulesMapper.insert(prodServiceOverAreaRules);
        // 返回
        return prodServiceOverAreaRules.getId();
    }

    @Override
    public void updateProdServiceOverAreaRules(ProdServiceOverAreaRulesSaveReqVO updateReqVO) {
        // 校验存在
        validateProdServiceOverAreaRulesExists(updateReqVO.getId());
        // 更新
        ProdServiceOverAreaRulesDO updateObj = BeanUtils.toBean(updateReqVO, ProdServiceOverAreaRulesDO.class);
        prodServiceOverAreaRulesMapper.updateById(updateObj);
    }

    @Override
    public void deleteProdServiceOverAreaRules(Long id) {
        // 校验存在
        validateProdServiceOverAreaRulesExists(id);
        // 删除
        prodServiceOverAreaRulesMapper.deleteById(id);
    }

    private void validateProdServiceOverAreaRulesExists(Long id) {
        if (prodServiceOverAreaRulesMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.PROD_SERVICE_OVER_AREA_RULES_NOT_EXISTS);
        }
    }

    @Override
    public ProdServiceOverAreaRulesDO getProdServiceOverAreaRules(Long id) {
        return prodServiceOverAreaRulesMapper.selectById(id);
    }

    @Override
    public PageResult<ProdServiceOverAreaRulesDO> getProdServiceOverAreaRulesPage(ProdServiceOverAreaRulesPageReqVO pageReqVO) {
        return null;
    }

}