package cn.ysk.cashier.controller;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.dto.TbVersionQueryCriteria;
import cn.ysk.cashier.pojo.TbVersion;
import cn.ysk.cashier.service.TbVersionService;
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.*;


@RestController
@RequiredArgsConstructor
@Api(tags = "版本管理")
@RequestMapping("/api/tbVersion")
public class TbVersionController {

    private final TbVersionService tbVersionService;

    @GetMapping
    @ApiOperation("查询版本")
    public ResponseEntity<Object> queryTbVersion(TbVersionQueryCriteria criteria){
        return new ResponseEntity<>(tbVersionService.queryAllPage(criteria),HttpStatus.OK);
    }

    @PostMapping
    @Log("版本管理 新增")
    @ApiOperation("新增版本")
    public ResponseEntity<Object> createTbVersion(@Validated @RequestBody TbVersion resources){
        return new ResponseEntity<>(tbVersionService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("版本管理 修改")
    @ApiOperation("修改版本")
    public ResponseEntity<Object> updateTbVersion(@Validated @RequestBody TbVersion resources){
        tbVersionService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @PutMapping("upSel")
    @Log("版本管理 修改选中")
    @ApiOperation("修改当前选中")
    public ResponseEntity<Object> updateSel(@Validated @RequestBody TbVersion resources){
        tbVersionService.updateSel(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


    @DeleteMapping
    @ApiOperation("删除版本")
    public ResponseEntity<Object> deleteTbVersion(@RequestBody Integer[] ids) {
        tbVersionService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}