package cn.ysk.cashier.cons.rest;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.cons.domain.ViewConSku;
import cn.ysk.cashier.cons.service.ViewConSkuService;
import cn.ysk.cashier.cons.service.dto.ViewConSkuQueryCriteria;
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.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author admin
* @date 2024-06-25
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "查询耗材规格信息管理")
@RequestMapping("/api/viewConSku")
public class ViewConSkuController {

    private final ViewConSkuService viewConSkuService;

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

    @GetMapping
    @ApiOperation("查询查询耗材规格信息")
    public ResponseEntity<Object> queryViewConSku(ViewConSkuQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(viewConSkuService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增查询耗材规格信息")
    @ApiOperation("新增查询耗材规格信息")
    public ResponseEntity<Object> createViewConSku(@Validated @RequestBody ViewConSku resources){
        return new ResponseEntity<>(viewConSkuService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改查询耗材规格信息")
    @ApiOperation("修改查询耗材规格信息")
    public ResponseEntity<Object> updateViewConSku(@Validated @RequestBody ViewConSku resources){
        viewConSkuService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除查询耗材规格信息")
    @ApiOperation("删除查询耗材规格信息")
    public ResponseEntity<Object> deleteViewConSku(@RequestBody Integer[] ids) {
        viewConSkuService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}