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

import com.tashow.cloud.product.dto.ProdServiceAreaRelevanceDO;
import com.tashow.cloud.product.mapper.ProdServiceAreaRelevanceMapper;
import com.tashow.cloud.product.service.ProdServiceAreaRelevanceService;
import com.tashow.cloud.product.vo.prodservicearearelevance.ProdServiceAreaRelevancePageReqVO;
import com.tashow.cloud.product.vo.prodservicearearelevance.ProdServiceAreaRelevanceSaveReqVO;
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 ProdServiceAreaRelevanceServiceImpl implements ProdServiceAreaRelevanceService {

    @Resource
    private ProdServiceAreaRelevanceMapper prodServiceAreaRelevanceMapper;

    @Override
    public Long createProdServiceAreaRelevance(ProdServiceAreaRelevanceSaveReqVO createReqVO) {
        // 插入
        ProdServiceAreaRelevanceDO prodServiceAreaRelevance = BeanUtils.toBean(createReqVO, ProdServiceAreaRelevanceDO.class);
        prodServiceAreaRelevanceMapper.insert(prodServiceAreaRelevance);
        // 返回
        return prodServiceAreaRelevance.getProdId();
    }

    @Override
    public void updateProdServiceAreaRelevance(ProdServiceAreaRelevanceSaveReqVO updateReqVO) {
        // 校验存在
        validateProdServiceAreaRelevanceExists(updateReqVO.getProdId());
        // 更新
        ProdServiceAreaRelevanceDO updateObj = BeanUtils.toBean(updateReqVO, ProdServiceAreaRelevanceDO.class);
        prodServiceAreaRelevanceMapper.updateById(updateObj);
    }

    @Override
    public void deleteProdServiceAreaRelevance(Long id) {
        // 校验存在
        validateProdServiceAreaRelevanceExists(id);
        // 删除
        prodServiceAreaRelevanceMapper.deleteById(id);
    }

    private void validateProdServiceAreaRelevanceExists(Long id) {
        if (prodServiceAreaRelevanceMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.PROD_SERVICE_AREA_RELEVANCE_NOT_EXISTS);
        }
    }

    @Override
    public ProdServiceAreaRelevanceDO getProdServiceAreaRelevance(Long id) {
        return prodServiceAreaRelevanceMapper.selectById(id);
    }

    @Override
    public PageResult<ProdServiceAreaRelevanceDO> getProdServiceAreaRelevancePage(ProdServiceAreaRelevancePageReqVO pageReqVO) {
        return null;
    }

}