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

import com.tashow.cloud.productapi.api.product.dto.ProdReservationConfigDO;
import com.tashow.cloud.product.mapper.ProdReservationConfigMapper;
import com.tashow.cloud.product.service.ProdReservationConfigService;
import com.tashow.cloud.productapi.api.product.vo.prodreservationconfig.ProdReservationConfigPageReqVO;
import com.tashow.cloud.productapi.api.product.vo.prodreservationconfig.ProdReservationConfigSaveReqVO;
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 ProdReservationConfigServiceImpl implements ProdReservationConfigService {

    @Resource
    private ProdReservationConfigMapper prodReservationConfigMapper;

    @Override
    public Long createProdReservationConfig(ProdReservationConfigSaveReqVO createReqVO) {
        // 插入
        ProdReservationConfigDO prodReservationConfig = BeanUtils.toBean(createReqVO, ProdReservationConfigDO.class);
        prodReservationConfigMapper.insert(prodReservationConfig);
        // 返回
        return prodReservationConfig.getId();
    }

    @Override
    public void updateProdReservationConfig(ProdReservationConfigSaveReqVO updateReqVO) {
        // 校验存在
        validateProdReservationConfigExists(updateReqVO.getId());
        // 更新
        ProdReservationConfigDO updateObj = BeanUtils.toBean(updateReqVO, ProdReservationConfigDO.class);
        prodReservationConfigMapper.updateById(updateObj);
    }

    @Override
    public void deleteProdReservationConfig(Long id) {
        // 校验存在
        validateProdReservationConfigExists(id);
        // 删除
        prodReservationConfigMapper.deleteById(id);
    }

    private void validateProdReservationConfigExists(Long id) {
        if (prodReservationConfigMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.PROD_RESERVATION_CONFIG_NOT_EXISTS);
        }
    }

    @Override
    public ProdReservationConfigDO getProdReservationConfig(Long id) {
        return prodReservationConfigMapper.selectById(id);
    }

    @Override
    public PageResult<ProdReservationConfigDO> getProdReservationConfigPage(ProdReservationConfigPageReqVO pageReqVO) {
        return null;
    }

}