package shop.alien.second.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import shop.alien.entity.result.R;
import shop.alien.entity.second.vo.SecondGoodsAdminQueryDTO;
import shop.alien.entity.second.vo.SecondGoodsDetailVo;
import shop.alien.entity.second.vo.SecondGoodsRecordDetailVo;
import shop.alien.entity.second.vo.SecondGoodsVo;
import shop.alien.second.service.SecondGoodsService;

/**
 * 二手商品管理后台控制器
 */
@Slf4j
@Api(tags = {"二手平台-商品管理(管理后台)"})
@ApiSort(2)
@CrossOrigin
@RestController
@RequestMapping("/admin/secondGoods")
@RequiredArgsConstructor
public class AdminSecondGoodsController {

    /**
     * 二手商品服务
     */
    private final SecondGoodsService secondGoodsService;

    /**
     * 管理后台商品列表接口
     */
    @PostMapping("/list")
    @ApiOperation("管理后台商品列表")
    public R<IPage<SecondGoodsVo>> getAdminGoodsList(@ApiParam("查询参数") @RequestBody SecondGoodsAdminQueryDTO queryDTO) {
        log.info("AdminSecondGoodsController.getAdminGoodsList?queryDTO={}", queryDTO);

        // 构建分页对象
        IPage<SecondGoodsVo> page = new Page<>(queryDTO.getPageNum(), queryDTO.getPageSize());

        // 执行分页查询
        IPage<SecondGoodsVo> result = secondGoodsService.getAdminGoodsList(page, queryDTO);
        
        return R.data(result, "查询成功");
    }
    
    @GetMapping("/detail")
    @ApiOperation("管理后台商品详情")
    public R<SecondGoodsDetailVo> getAdminGoodsDetail(@ApiParam("商品ID") @RequestParam Integer goodsId) throws Exception {
        log.info("AdminSecondGoodsController.getAdminGoodsDetail?goodsId={}", goodsId);
        
        SecondGoodsDetailVo result = secondGoodsService.getAdminGoodsDetail(goodsId);
        
        return R.data(result, "查询成功");
    }

    @GetMapping("/record/detail")
    @ApiOperation("管理后台商品操作记录详情")
    public R<SecondGoodsRecordDetailVo> getAdminGoodsRecordDetail(@ApiParam("操作记录ID") @RequestParam Integer recordId) {
        log.info("AdminSecondGoodsController.getAdminGoodsRecordDetail?recordId={}", recordId);

        SecondGoodsRecordDetailVo result = secondGoodsService.getAdminGoodsRecordDetail(recordId);

        return R.data(result, "查询成功");
    }
}