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

import com.tashow.cloud.product.dto.ProdServiceAreasDO;
import com.tashow.cloud.product.mapper.ProdServiceAreasMapper;
import com.tashow.cloud.product.service.ProdServiceAreasService;
import com.tashow.cloud.product.vo.prodserviceareas.ProdServiceAreasPageReqVO;
import com.tashow.cloud.product.vo.prodserviceareas.ProdServiceAreasSaveReqVO;
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 ProdServiceAreasServiceImpl implements ProdServiceAreasService {

    @Resource
    private ProdServiceAreasMapper prodServiceAreasMapper;

    @Override
    public Long createProdServiceAreas(ProdServiceAreasSaveReqVO createReqVO) {
        // 插入
        ProdServiceAreasDO prodServiceAreas = BeanUtils.toBean(createReqVO, ProdServiceAreasDO.class);
        prodServiceAreasMapper.insert(prodServiceAreas);
        // 返回
        return prodServiceAreas.getId();
    }

    @Override
    public void updateProdServiceAreas(ProdServiceAreasSaveReqVO updateReqVO) {
        // 校验存在
        validateProdServiceAreasExists(updateReqVO.getId());
        // 更新
        ProdServiceAreasDO updateObj = BeanUtils.toBean(updateReqVO, ProdServiceAreasDO.class);
        prodServiceAreasMapper.updateById(updateObj);
    }

    @Override
    public void deleteProdServiceAreas(Long id) {
        // 校验存在
        validateProdServiceAreasExists(id);
        // 删除
        prodServiceAreasMapper.deleteById(id);
    }

    private void validateProdServiceAreasExists(Long id) {
        if (prodServiceAreasMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.PROD_SERVICE_AREAS_NOT_EXISTS);
        }
    }

    @Override
    public ProdServiceAreasDO getProdServiceAreas(Long id) {
        return prodServiceAreasMapper.selectById(id);
    }

    @Override
    public PageResult<ProdServiceAreasDO> getProdServiceAreasPage(ProdServiceAreasPageReqVO pageReqVO) {
        return null;
    }

}