package cn.ysk.cashier.controller.shop;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.pojo.shop.TbCouponCategory;
import cn.ysk.cashier.dto.shop.TbCouponCategoryQueryCriteria;
import cn.ysk.cashier.service.shop.TbCouponCategoryService;
import org.springframework.data.domain.Pageable;
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 ww
 * @date 2024-04-25
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "团购卷类别管理")
@RequestMapping("/api/tbCouponCategory")
public class TbCouponCategoryController {

    private final TbCouponCategoryService tbCouponCategoryService;

    @GetMapping
    @ApiOperation("查询团购卷类别")
    public ResponseEntity<Object> queryTbCouponCategory(TbCouponCategoryQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(tbCouponCategoryService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增团购卷类别")
    @ApiOperation("新增团购卷类别")
    public ResponseEntity<Object> createTbCouponCategory(@Validated @RequestBody TbCouponCategory resources){
        return new ResponseEntity<>(tbCouponCategoryService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改团购卷类别")
    @ApiOperation("修改团购卷类别")
    public ResponseEntity<Object> updateTbCouponCategory(@Validated @RequestBody TbCouponCategory resources){
        tbCouponCategoryService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除团购卷类别")
    @ApiOperation("删除团购卷类别")
    public ResponseEntity<Object> deleteTbCouponCategory(@RequestBody Integer[] ids) {
        tbCouponCategoryService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}