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

import com.tashow.cloud.productapi.api.product.dto.SkuServicesFormDO;
import com.tashow.cloud.product.mapper.SkuServicesFormMapper;
import com.tashow.cloud.product.service.SkuServicesFormService;
import com.tashow.cloud.productapi.api.product.vo.skuservicesform.SkuServicesFormPageReqVO;
import com.tashow.cloud.productapi.api.product.vo.skuservicesform.SkuServicesFormSaveReqVO;
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;

/**
 * 商品SKU扩展服务表单 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class SkuServicesFormServiceImpl implements SkuServicesFormService {

    @Resource
    private SkuServicesFormMapper skuServicesFormMapper;

    @Override
    public Long createSkuServicesForm(SkuServicesFormSaveReqVO createReqVO) {
        // 插入
        SkuServicesFormDO skuServicesForm = BeanUtils.toBean(createReqVO, SkuServicesFormDO.class);
        skuServicesFormMapper.insert(skuServicesForm);
        // 返回
        return skuServicesForm.getId();
    }

    @Override
    public void updateSkuServicesForm(SkuServicesFormSaveReqVO updateReqVO) {
        // 校验存在
        validateSkuServicesFormExists(updateReqVO.getId());
        // 更新
        SkuServicesFormDO updateObj = BeanUtils.toBean(updateReqVO, SkuServicesFormDO.class);
        skuServicesFormMapper.updateById(updateObj);
    }

    @Override
    public void deleteSkuServicesForm(Long id) {
        // 校验存在
        validateSkuServicesFormExists(id);
        // 删除
        skuServicesFormMapper.deleteById(id);
    }

    private void validateSkuServicesFormExists(Long id) {
        if (skuServicesFormMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.SKU_SERVICES_FORM_NOT_EXISTS);
        }
    }

    @Override
    public SkuServicesFormDO getSkuServicesForm(Long id) {
        return skuServicesFormMapper.selectById(id);
    }

    @Override
    public PageResult<SkuServicesFormDO> getSkuServicesFormPage(SkuServicesFormPageReqVO pageReqVO) {
        return null;
    }

}