package com.seer.teach.mall.good.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.common.enums.EntityDeleteFlagEnums;
import com.seer.teach.common.utils.PageConverterUtils;
import com.seer.teach.mall.convert.GoodConverter;
import com.seer.teach.mall.entity.GoodsEntity;
import com.seer.teach.mall.entity.GoodsLogEntity;
import com.seer.teach.mall.good.service.IAdminGoodsLogService;
import com.seer.teach.mall.good.service.IAdminGoodsService;
import com.seer.teach.mall.request.GoodsAuditReq;
import com.seer.teach.mall.request.GoodsReq;
import com.seer.teach.mall.response.GoodLogsResp;
import com.seer.teach.mall.response.GoodsResp;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *  商品日志后台管理控制器
 */
@RestController
@RequestMapping("/mall/goods/log")
@Tag(name = "管理端 - 商品管理")
@Validated
@RequiredArgsConstructor
@SaCheckLogin(type = StpUtil.TYPE)
public class AdminGoodsLogController {


    private final IAdminGoodsLogService goodsLogService;

    /**
     * 分页列表
     */
    @Operation(summary = "商品日志分页查询")
    @GetMapping("/{goodsId}/{pageSize}/{pageNo}")
    @SaCheckPermission("admin:goods:logs:page")
    public ResultBean<PageListBean<GoodLogsResp>> queryPageList(
            @Parameter(description = "商品id") @PathVariable("goodsId") Integer goodsId,
            @Parameter(description = "每页数量") @PathVariable("pageSize") Integer pageSize,
            @Parameter(description = "第几页") @PathVariable("pageNo") Integer pageNo) {
        IPage<GoodsLogEntity> iPage = goodsLogService.queryPageList(goodsId,pageSize, pageNo);
        PageListBean<GoodLogsResp> result = PageConverterUtils.convertPageListBean(iPage, GoodConverter.INSTANCE::toGoodsLogEntityList);
        return ResultBean.success(result);
    }
}