/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package cn.ysk.cashier.controller.shop;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.service.shop.TbPrintMachineService;
import cn.ysk.cashier.dto.shop.PrintMachineDto;
import cn.ysk.cashier.dto.shop.TbPrintMachineQueryCriteria;
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 lyf
* @date 2024-02-28
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "/shop/print管理")
@RequestMapping("/api/tbPrintMachine")
public class TbPrintMachineController {

    private final TbPrintMachineService tbPrintMachineService;

//    @Log("导出数据")
//    @ApiOperation("导出数据")
//    @GetMapping(value = "/download")
//    public void exportTbPrintMachine(HttpServletResponse response, TbPrintMachineQueryCriteria criteria) throws IOException {
//        tbPrintMachineService.download(tbPrintMachineService.queryAll(criteria), response);
//    }

    @GetMapping
    @ApiOperation("查询/shop/print")
    public ResponseEntity<Object> queryTbPrintMachine(TbPrintMachineQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(tbPrintMachineService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增打印机:#resources.name")
    @ApiOperation("新增/shop/print")
    public ResponseEntity<Object> createTbPrintMachine(@Validated @RequestBody PrintMachineDto resources){
        return new ResponseEntity<>(tbPrintMachineService.create(resources),HttpStatus.CREATED);
    }
    @GetMapping("/{id}")
    public ResponseEntity<Object> createTbPrintMachine(@PathVariable Integer id){
        return new ResponseEntity<>(tbPrintMachineService.findById(id),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改打印机:#resources.name")
    @ApiOperation("修改/shop/print")
    public ResponseEntity<Object> updateTbPrintMachine(@Validated @RequestBody PrintMachineDto resources){
        tbPrintMachineService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除打印机:#ids")
    @ApiOperation("删除/shop/print")
    public ResponseEntity<Object> deleteTbPrintMachine(@RequestBody Integer[] ids) {
        tbPrintMachineService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}