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

import com.tashow.cloud.product.dto.ProdAdditionalFeeDatesDO;
import com.tashow.cloud.product.mapper.ProdAdditionalFeeDatesMapper;
import com.tashow.cloud.product.service.ProdAdditionalFeeDatesService;
import com.tashow.cloud.product.vo.prodadditionalfeedates.ProdAdditionalFeeDatesPageReqVO;
import com.tashow.cloud.product.vo.prodadditionalfeedates.ProdAdditionalFeeDatesSaveReqVO;
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 ProdAdditionalFeeDatesServiceImpl implements ProdAdditionalFeeDatesService {

    @Resource
    private ProdAdditionalFeeDatesMapper prodAdditionalFeeDatesMapper;

    @Override
    public Long createProdAdditionalFeeDates(ProdAdditionalFeeDatesSaveReqVO createReqVO) {
        // 插入
        ProdAdditionalFeeDatesDO prodAdditionalFeeDates = BeanUtils.toBean(createReqVO, ProdAdditionalFeeDatesDO.class);
        prodAdditionalFeeDatesMapper.insert(prodAdditionalFeeDates);
        // 返回
        return prodAdditionalFeeDates.getId();
    }

    @Override
    public void updateProdAdditionalFeeDates(ProdAdditionalFeeDatesSaveReqVO updateReqVO) {
        // 校验存在
        validateProdAdditionalFeeDatesExists(updateReqVO.getId());
        // 更新
        ProdAdditionalFeeDatesDO updateObj = BeanUtils.toBean(updateReqVO, ProdAdditionalFeeDatesDO.class);
        prodAdditionalFeeDatesMapper.updateById(updateObj);
    }

    @Override
    public void deleteProdAdditionalFeeDates(Long id) {
        // 校验存在
        validateProdAdditionalFeeDatesExists(id);
        // 删除
        prodAdditionalFeeDatesMapper.deleteById(id);
    }

    private void validateProdAdditionalFeeDatesExists(Long id) {
        if (prodAdditionalFeeDatesMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.PROD_ADDITIONAL_FEE_DATES_NOT_EXISTS);
        }
    }

    @Override
    public ProdAdditionalFeeDatesDO getProdAdditionalFeeDates(Long id) {
        return prodAdditionalFeeDatesMapper.selectById(id);
    }

    @Override
    public PageResult<ProdAdditionalFeeDatesDO> getProdAdditionalFeeDatesPage(ProdAdditionalFeeDatesPageReqVO pageReqVO) {
        return null;
    }

}