package cn.ysk.cashier.controller.shop;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.dto.shop.ShopStorageGoodDto;
import cn.ysk.cashier.pojo.shop.TbShopStorageGood;
import cn.ysk.cashier.dto.shop.TbShopStorageGoodQueryCriteria;
import cn.ysk.cashier.service.shop.TbShopStorageGoodService;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Sort;
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 java.util.List;
import javax.servlet.http.HttpServletResponse;

/**
 * @author ww
 * @date 2024-05-21
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "酒品管理")
@RequestMapping("/api/tbShopStorageGood")
public class TbShopStorageGoodController {

    private final TbShopStorageGoodService tbShopStorageGoodService;

//    @ApiOperation("导出酒品数据")
//    @GetMapping(value = "/download")
//    public void exportTbShopStorageGood(HttpServletResponse response, TbShopStorageGoodQueryCriteria criteria) throws IOException {
//        tbShopStorageGoodService.download(tbShopStorageGoodService.queryAll(criteria), response);
//    }

    @PostMapping("list")
    @ApiOperation("查询酒品列表")
    public ResponseEntity<Object> queryTbShopStorageGood(@RequestBody TbShopStorageGoodQueryCriteria criteria){
        Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getSize(), Sort.by(Sort.Direction.DESC, "id"));
        return new ResponseEntity<>(tbShopStorageGoodService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增酒品")
    @ApiOperation("新增酒品")
    public ResponseEntity<Object> createTbShopStorageGood(@Validated @RequestBody ShopStorageGoodDto resources){
        tbShopStorageGoodService.create(resources);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改酒品:#resources.name")
    @ApiOperation("修改酒品")
    public ResponseEntity<Object> updateTbShopStorageGood(@Validated @RequestBody TbShopStorageGood resources){
        tbShopStorageGoodService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
//
//    @DeleteMapping
//    @Log("删除酒品")
//    @ApiOperation("删除酒品")
//    public ResponseEntity<Object> deleteTbShopStorageGood(@RequestBody Integer[] ids) {
//        tbShopStorageGoodService.deleteAll(ids);
//        return new ResponseEntity<>(HttpStatus.OK);
//    }
}