package cn.ysk.cashier.controller.product;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.pojo.product.TbShopCategory;
import cn.ysk.cashier.service.product.TbShopCategoryService;
import cn.ysk.cashier.dto.product.TbShopCategoryQueryCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

/**
* @website https://eladmin.vip
* @author lyf
* @date 2024-01-08
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "product/category管理")
@RequestMapping("/api/tbShopCategory")
public class TbShopCategoryController {

    private final TbShopCategoryService tbShopCategoryService;

//    @Log("导出数据")
//    @ApiOperation("导出数据")
//    @GetMapping(value = "/download")
//    @PreAuthorize("@el.check('tbShopCategory:list')")
//    public void exportTbShopCategory(HttpServletResponse response, TbShopCategoryQueryCriteria criteria) throws IOException {
//        tbShopCategoryService.download(tbShopCategoryService.queryAll(criteria), response);
//    }

    @GetMapping
    @ApiOperation("查询product/category")
    public ResponseEntity<Object> queryTbShopCategory(TbShopCategoryQueryCriteria criteria){
        return new ResponseEntity<>(tbShopCategoryService.queryAll(criteria),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增商品分类:#resources.name")
    @ApiOperation("新增product/category")
    public ResponseEntity<Object> createTbShopCategory(@Validated @RequestBody TbShopCategory resources){
        return new ResponseEntity<>(tbShopCategoryService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改商品分类:#resources.name")
    @ApiOperation("修改product/category")
    public ResponseEntity<Object> updateTbShopCategory(@Validated @RequestBody TbShopCategory resources){
        tbShopCategoryService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除商品分类:#ids")
    @ApiOperation("删除product/category")
    public ResponseEntity<Object> deleteTbShopCategory(@RequestBody Integer[] ids) {

        tbShopCategoryService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}