package com.ruoyi.web.controller.mall;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.mall.domain.ProductShow;
import com.ruoyi.mall.domain.vo.ProductShowVO;
import com.ruoyi.mall.service.ProductShowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品展示申请
 */
@Api(description ="商品展示申请接口列表")
@RestController
@RequestMapping("/pms/productShow")
public class ProductShowController extends BaseController {
    @Autowired
    private ProductShowService service;

    @ApiOperation("查询商品信息列表")
    @PostMapping("/list")
    public ResponseEntity<Page<ProductShowVO>> list(@RequestBody ProductShowVO query, Pageable page) {
        List<ProductShowVO> list = service.selectByEntity(query, page);
        return ResponseEntity.ok(new PageImpl<>(list, page, ((com.github.pagehelper.Page)list).getTotal()));
    }

    @GetMapping(value = "/{id}")
    public ResponseEntity<ProductShow> getInfo(@PathVariable("id") Long id) {
        ProductShow productShow= service.selectProductShowDetail(id);
        return ResponseEntity.ok(productShow);
    }


    @ApiOperation("新增商品申请（租户）")
    @PreAuthorize("@ss.hasPermi('pms:publishProduct:list')")
    @PostMapping
    public ResponseEntity<Boolean> add(@RequestBody ProductShow productShow) {
        return ResponseEntity.ok(service.insertProductShow(productShow));
    }



    @ApiOperation("修改申请（租户）")
    @PreAuthorize("@ss.hasPermi('pms:publishProduct:list')")
    @PutMapping
    public ResponseEntity<Boolean> edit(@RequestBody ProductShow productShowUpdate) {
        return ResponseEntity.ok(service.updateProductShow(productShowUpdate));
    }

    @ApiOperation("取消申请/删除（租户）")
    @PreAuthorize("@ss.hasPermi('pms:publishProduct:list')")
	@DeleteMapping("/{id}")
    public ResponseEntity<Boolean> remove(@PathVariable Long id) {
        return ResponseEntity.ok(service.deleteProductShow(id));
    }

    //拒绝商品展示
    @ApiOperation("拒绝商品展示（管理员）")
    @PreAuthorize("@ss.hasPermi('pms:review:list')")
    @PutMapping("/refuse")
    public ResponseEntity<Boolean> refuse(@RequestBody ProductShow productShowUpdate) {
        return ResponseEntity.ok(service.refuseProductShow(productShowUpdate.getId()));
    }

    //审核通过
    @ApiOperation("审核通过（管理员）")
    @PreAuthorize("@ss.hasPermi('pms:review:list')")
    @PutMapping("/pass")
    public ResponseEntity<Boolean> pass(@RequestBody ProductShow productShowUpdate) {
        return ResponseEntity.ok(service.passProductShow(productShowUpdate));
    }
}
