package com.cool.store.controller.webb;

import com.alibaba.fastjson.JSONObject;
import com.cool.store.context.CurrentUserHolder;
import com.cool.store.dto.pre.fry.PreFriedProductsBatchDTO;
import com.cool.store.dto.pre.fry.PreFriedProductsDTO;
import com.cool.store.dto.pre.fry.PreFriedProductsDetailDTO;
import com.cool.store.dto.pre.fry.PreFriedProductsQueryDTO;
import com.cool.store.request.AddPointDetailRequest;
import com.cool.store.response.ResponseResult;
import com.cool.store.service.PreFriedProductsService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author suzhuhong
 * @Date 2025/6/21 13:19
 * @Version 1.0
 */
@Slf4j
@Api(tags = "预炸")
@RestController
@RequestMapping("/pc/pre/fry/")
public class PreFryController {

    @Resource
    PreFriedProductsService preFriedProductsService;

    @ApiOperation("新增预炸品")
    @PostMapping("/add")
    public ResponseResult<Long> createProduct(@RequestBody @Validated PreFriedProductsDTO dto) {
        log.info("新增预炸品：{}", JSONObject.toJSONString(dto));
        return ResponseResult.success(preFriedProductsService.createProduct( dto, CurrentUserHolder.getUser().getUserId()));
    }

    @ApiOperation("修改预炸品")
    @PostMapping("/update")
    public ResponseResult<Long> updateProduct(@RequestBody @Validated PreFriedProductsDTO dto) {
        log.info("修改预炸品：{}", JSONObject.toJSONString(dto));
        return ResponseResult.success(preFriedProductsService.updateProduct( dto, CurrentUserHolder.getUser().getUserId()));
    }

    @ApiOperation("批量删除预炸品")
    @PostMapping("/batchDelete")
    public ResponseResult<Integer> batchDelete(@RequestBody @Validated PreFriedProductsBatchDTO dto) {
        log.info("批量删除预炸品：{}", JSONObject.toJSONString(dto));
        return ResponseResult.success(preFriedProductsService.batchDelete( dto, CurrentUserHolder.getUser().getUserId()));
    }


    @ApiOperation("批量上下架商品")
    @PostMapping("/batchUpdateStatus")
    public ResponseResult<Integer> batchUpdateStatus(@RequestBody @Validated PreFriedProductsBatchDTO dto) {
        log.info("批量删除预炸品：{}", JSONObject.toJSONString(dto));
        return ResponseResult.success(preFriedProductsService.batchUpdateStatus( dto, CurrentUserHolder.getUser().getUserId()));
    }

    @ApiOperation("查询预炸品列表")
    @PostMapping("/queryProducts")
    public ResponseResult<PageInfo<PreFriedProductsDetailDTO>> queryProducts(@RequestBody @Validated PreFriedProductsQueryDTO dto) {
        log.info("查询预炸品：{}", JSONObject.toJSONString(dto));
        return ResponseResult.success(preFriedProductsService.queryProducts(dto));
    }


    @ApiOperation("查询预炸品详情")
    @GetMapping("/queryById")
    public ResponseResult<PreFriedProductsDetailDTO> queryById(@RequestParam(required = true, value = "productId") Long productId) {
        log.info("查询预炸品：{}", JSONObject.toJSONString(productId));
        return ResponseResult.success(preFriedProductsService.queryById(productId));
    }




}
