package com.tashow.cloud.product.api;

import com.tashow.cloud.common.pojo.CommonResult;
import com.tashow.cloud.common.pojo.PageResult;
import com.tashow.cloud.product.service.ProdService;
import com.tashow.cloud.product.service.SkuService;
import com.tashow.cloud.productapi.api.product.ProdApi;
import com.tashow.cloud.productapi.api.product.dto.ProdDO;
import com.tashow.cloud.productapi.api.product.vo.prod.ProdListVO;
import com.tashow.cloud.productapi.api.product.vo.prod.ProdPageReqVO;
import com.tashow.cloud.productapi.api.product.vo.prod.ProdServiceVO;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import static com.tashow.cloud.common.pojo.CommonResult.success;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@Validated
public class ProdImpl implements ProdApi {

    @Resource
    private ProdService prodService;

    @Resource
    private SkuService skuService;

    @Override
    public CommonResult<ProdDO> getProdInfo(Long id) {
        return CommonResult.success(prodService.getProd(id));
    }

    @Override
    public ProdServiceVO getProdService(Long id) {
        return prodService.getProdService(id);
    }

    @Override
    public PageResult<ProdListVO> getProdPage(ProdPageReqVO pageReqVO) {
        return prodService.getProdPage(pageReqVO);
    }

    @Override
    public CommonResult<Boolean> reduceStocks(Long skuId, Integer stocksNum) {
        skuService.reduceStocks(skuId, stocksNum);
        return success(true);
    }

    @Override
    public CommonResult<Boolean> increaseStocks(Long skuId, Integer stocksNum) {
        skuService.increaseStocks(skuId, stocksNum);
        return success(true);
    }

}
