package com.gree.mall.miniapp.controller.goods;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.goods.GoodsLeaseLogic;
import com.gree.mall.miniapp.plus.entity.GoodsCategory;
import com.gree.mall.miniapp.plus.entity.GoodsLease;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@Api(value = "租赁商品列表", tags ={"租赁商品列表"} )
@RequestMapping(value = "/goods/lease", produces = "application/json; charset=utf-8")
public class GoodsLeaseController {

    @Resource
    GoodsLeaseLogic goodsLeaseLogic;

    @PostMapping("/list/page")
    @ApiOperation(value = "商品列表")
    public ResponseHelper<IPage<GoodsLease>> page(
            HttpServletRequest request,
            @ApiParam(value = "分类id") @RequestParam(required = false) String categoryId,
            @ApiParam(value = "商品名称") @RequestParam(required = false) String name,
            @ApiParam(value = "页号",required = true) @RequestParam Integer pageNum,
            @ApiParam(value = "页大小",required = true) @RequestParam Integer pageSize
    ) throws Exception {
        IPage<GoodsLease> page = goodsLeaseLogic.page(request, categoryId, name, pageNum, pageSize);
        return ResponseHelper.success(page);
    }


    @PostMapping("/category/list")
    @ApiOperation(value = "分类列表")
    public ResponseHelper<List<GoodsCategory>> categoryList(
            HttpServletRequest request,
            @ApiParam(value = "分类名称") @RequestParam(required = false) String categoryName
    ) throws Exception {
        List<GoodsCategory> categoryList = goodsLeaseLogic.categoryList(request, categoryName);
        return ResponseHelper.success(categoryList);
    }

    @PostMapping("/detail")
    @ApiOperation(value = "商品详情")
    public ResponseHelper<GoodsLease> detail(
            HttpServletRequest request,
            @ApiParam(value = "商品id",required = true) @RequestParam String id
    ) throws Exception {
        GoodsLease page = goodsLeaseLogic.detail(request, id);
        return ResponseHelper.success(page);
    }

}
