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

import com.tashow.cloud.product.dto.ShopDetailDO;
import com.tashow.cloud.product.mapper.ShopDetailMapper;
import com.tashow.cloud.product.service.ShopDetailService;
import com.tashow.cloud.product.vo.shopdetail.ShopDetailPageReqVO;
import com.tashow.cloud.product.vo.shopdetail.ShopDetailSaveReqVO;
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 ShopDetailServiceImpl implements ShopDetailService {

    @Resource
    private ShopDetailMapper shopDetailMapper;

    @Override
    public Long createShopDetail(ShopDetailSaveReqVO createReqVO) {
        // 插入
        ShopDetailDO shopDetail = BeanUtils.toBean(createReqVO, ShopDetailDO.class);
        shopDetailMapper.insert(shopDetail);
        // 返回
        return shopDetail.getShopId();
    }

    @Override
    public void updateShopDetail(ShopDetailSaveReqVO updateReqVO) {
        // 校验存在
        validateShopDetailExists(updateReqVO.getShopId());
        // 更新
        ShopDetailDO updateObj = BeanUtils.toBean(updateReqVO, ShopDetailDO.class);
        shopDetailMapper.updateById(updateObj);
    }

    @Override
    public void deleteShopDetail(Long id) {
        // 校验存在
        validateShopDetailExists(id);
        // 删除
        shopDetailMapper.deleteById(id);
    }

    private void validateShopDetailExists(Long id) {
        if (shopDetailMapper.selectById(id) == null) {
            throw exception(ErrorCodeConstants.SHOP_DETAIL_NOT_EXISTS);
        }
    }

    @Override
    public ShopDetailDO getShopDetail(Long id) {
        return shopDetailMapper.selectById(id);
    }

    @Override
    public PageResult<ShopDetailDO> getShopDetailPage(ShopDetailPageReqVO pageReqVO) {
        return null;
    }

}