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

import com.tashow.cloud.productapi.api.product.dto.SkuServiceDetailsDO;
import com.tashow.cloud.product.mapper.SkuServiceDetailsMapper;
import com.tashow.cloud.product.service.SkuServiceDetailsService;
import com.tashow.cloud.productapi.api.product.vo.skuservicedetails.SkuServiceDetailsPageReqVO;
import com.tashow.cloud.productapi.api.product.vo.skuservicedetails.SkuServiceDetailsSaveReqVO;
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 SkuServiceDetailsServiceImpl implements SkuServiceDetailsService {

    @Resource
    private SkuServiceDetailsMapper skuServiceDetailsMapper;

    @Override
    public Long createSkuServiceDetails(SkuServiceDetailsSaveReqVO createReqVO) {
        // 插入
        SkuServiceDetailsDO skuServiceDetails = BeanUtils.toBean(createReqVO, SkuServiceDetailsDO.class);
        skuServiceDetailsMapper.insert(skuServiceDetails);
        // 返回
        return skuServiceDetails.getId();
    }

    @Override
    public void updateSkuServiceDetails(SkuServiceDetailsSaveReqVO updateReqVO) {
        // 校验存在
        validateSkuServiceDetailsExists(updateReqVO.getId());
        // 更新
        SkuServiceDetailsDO updateObj = BeanUtils.toBean(updateReqVO, SkuServiceDetailsDO.class);
        skuServiceDetailsMapper.updateById(updateObj);
    }

    @Override
    public void deleteSkuServiceDetails(Long id) {
        // 校验存在
        validateSkuServiceDetailsExists(id);
        // 删除
        skuServiceDetailsMapper.deleteById(id);
    }

    private void validateSkuServiceDetailsExists(Long id) {
        if (skuServiceDetailsMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.SKU_SERVICE_DETAILS_NOT_EXISTS);
        }
    }

    @Override
    public SkuServiceDetailsDO getSkuServiceDetails(Long id) {
        return skuServiceDetailsMapper.selectById(id);
    }

    @Override
    public PageResult<SkuServiceDetailsDO> getSkuServiceDetailsPage(SkuServiceDetailsPageReqVO pageReqVO) {
        return null;
    }

}