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

import com.tashow.cloud.product.dto.ProdWeightRangePricesDO;
import com.tashow.cloud.product.mapper.ProdWeightRangePricesMapper;
import com.tashow.cloud.product.service.ProdWeightRangePricesService;
import com.tashow.cloud.product.vo.prodweightrangeprices.ProdWeightRangePricesPageReqVO;
import com.tashow.cloud.product.vo.prodweightrangeprices.ProdWeightRangePricesSaveReqVO;
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 ProdWeightRangePricesServiceImpl implements ProdWeightRangePricesService {

    @Resource
    private ProdWeightRangePricesMapper prodWeightRangePricesMapper;

    @Override
    public Long createProdWeightRangePrices(ProdWeightRangePricesSaveReqVO createReqVO) {
        // 插入
        ProdWeightRangePricesDO prodWeightRangePrices = BeanUtils.toBean(createReqVO, ProdWeightRangePricesDO.class);
        prodWeightRangePricesMapper.insert(prodWeightRangePrices);
        // 返回
        return prodWeightRangePrices.getId();
    }

    @Override
    public void updateProdWeightRangePrices(ProdWeightRangePricesSaveReqVO updateReqVO) {
        // 校验存在
        validateProdWeightRangePricesExists(updateReqVO.getId());
        // 更新
        ProdWeightRangePricesDO updateObj = BeanUtils.toBean(updateReqVO, ProdWeightRangePricesDO.class);
        prodWeightRangePricesMapper.updateById(updateObj);
    }

    @Override
    public void deleteProdWeightRangePrices(Long id) {
        // 校验存在
        validateProdWeightRangePricesExists(id);
        // 删除
        prodWeightRangePricesMapper.deleteById(id);
    }

    private void validateProdWeightRangePricesExists(Long id) {
        if (prodWeightRangePricesMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.PROD_WEIGHT_RANGE_PRICES_NOT_EXISTS);
        }
    }

    @Override
    public ProdWeightRangePricesDO getProdWeightRangePrices(Long id) {
        return prodWeightRangePricesMapper.selectById(id);
    }

    @Override
    public PageResult<ProdWeightRangePricesDO> getProdWeightRangePricesPage(ProdWeightRangePricesPageReqVO pageReqVO) {
        return null;
    }

}