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

import com.tashow.cloud.product.dto.ProdAdditionalFeePeriodsDO;
import com.tashow.cloud.product.mapper.ProdAdditionalFeePeriodsMapper;
import com.tashow.cloud.product.service.ProdAdditionalFeePeriodsService;
import com.tashow.cloud.product.vo.prodadditionalfeeperiods.ProdAdditionalFeePeriodsPageReqVO;
import com.tashow.cloud.product.vo.prodadditionalfeeperiods.ProdAdditionalFeePeriodsSaveReqVO;
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 ProdAdditionalFeePeriodsServiceImpl implements ProdAdditionalFeePeriodsService {

    @Resource
    private ProdAdditionalFeePeriodsMapper prodAdditionalFeePeriodsMapper;

    @Override
    public Long createProdAdditionalFeePeriods(ProdAdditionalFeePeriodsSaveReqVO createReqVO) {
        // 插入
        ProdAdditionalFeePeriodsDO prodAdditionalFeePeriods = BeanUtils.toBean(createReqVO, ProdAdditionalFeePeriodsDO.class);
        prodAdditionalFeePeriodsMapper.insert(prodAdditionalFeePeriods);
        // 返回
        return prodAdditionalFeePeriods.getId();
    }

    @Override
    public void updateProdAdditionalFeePeriods(ProdAdditionalFeePeriodsSaveReqVO updateReqVO) {
        // 校验存在
        validateProdAdditionalFeePeriodsExists(updateReqVO.getId());
        // 更新
        ProdAdditionalFeePeriodsDO updateObj = BeanUtils.toBean(updateReqVO, ProdAdditionalFeePeriodsDO.class);
        prodAdditionalFeePeriodsMapper.updateById(updateObj);
    }

    @Override
    public void deleteProdAdditionalFeePeriods(Long id) {
        // 校验存在
        validateProdAdditionalFeePeriodsExists(id);
        // 删除
        prodAdditionalFeePeriodsMapper.deleteById(id);
    }

    private void validateProdAdditionalFeePeriodsExists(Long id) {
        if (prodAdditionalFeePeriodsMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.PROD_ADDITIONAL_FEE_PERIODS_NOT_EXISTS);
        }
    }

    @Override
    public ProdAdditionalFeePeriodsDO getProdAdditionalFeePeriods(Long id) {
        return prodAdditionalFeePeriodsMapper.selectById(id);
    }

    @Override
    public PageResult<ProdAdditionalFeePeriodsDO> getProdAdditionalFeePeriodsPage(ProdAdditionalFeePeriodsPageReqVO pageReqVO) {
        return null;
    }

}