package cn.ysk.cashier.controller.product;

import cn.ysk.cashier.dto.product.PadProductCategoryDTO;
import cn.ysk.cashier.mybatis.service.TbPadProductCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Pad商品自定义分类
 * @author tankaikai
 * @since 2024-10-22 16:38
 */
@RestController
@RequestMapping("/api/pad/productCategory")
@Api(tags="Pad商品自定义分类")
public class TbPadProductCategoryController {

    @Resource
    private TbPadProductCategoryService mpPadProductCategoryService;

    @GetMapping("page")
    @ApiOperation("分页")
    public ResponseEntity page(@RequestParam Map<String, Object> params) {
        Map<String, Object> page = mpPadProductCategoryService.findPage(params);
        return ResponseEntity.ok().body(page);
    }

    @GetMapping("{id}")
    @ApiOperation("详情")
    public ResponseEntity get(@PathVariable("id") Long id) {
        PadProductCategoryDTO data = mpPadProductCategoryService.get(id);
        return ResponseEntity.ok().body(data);
    }

    @PostMapping
    @ApiOperation("保存")
    public ResponseEntity save(@RequestBody PadProductCategoryDTO dto) {
        mpPadProductCategoryService.save(dto);
        return ResponseEntity.ok().body(dto.getId());
    }

    @PutMapping
    @ApiOperation("修改")
    public ResponseEntity update(@RequestBody PadProductCategoryDTO dto) {
        mpPadProductCategoryService.update(dto);
        return ResponseEntity.ok().body(dto.getId());
    }

    @DeleteMapping("{id}")
    @ApiOperation("删除")
    public ResponseEntity delete(@PathVariable("id") Long id) {
        mpPadProductCategoryService.delete(id);
        return ResponseEntity.ok().build();
    }

    @PostMapping("sort")
    @ApiOperation("排序")
    public ResponseEntity sort(@RequestBody List<PadProductCategoryDTO> sortList) {
        mpPadProductCategoryService.sort(sortList);
        return ResponseEntity.ok().build();
    }

    @PostMapping("copy/{id}")
    @ApiOperation("复制")
    public ResponseEntity copy(@PathVariable("id") Long id) {
        mpPadProductCategoryService.copy(id);
        return ResponseEntity.ok().build();
    }

}
