package cn.ysk.cashier.cons.rest;

import cn.ysk.cashier.annotation.Log;
import cn.ysk.cashier.cons.domain.ViewProductSkuShop;
import cn.ysk.cashier.cons.service.ViewProductSkuShopService;
import cn.ysk.cashier.cons.service.dto.ViewProductSkuShopQueryCriteria;
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/viewProductSkuShop")
public class ViewProductSkuShopController {

    private final ViewProductSkuShopService viewProductSkuShopService;

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

    @GetMapping
    @ApiOperation("查询商品规格信息查询")
    public ResponseEntity<Object> queryViewProductSkuShop(ViewProductSkuShopQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(viewProductSkuShopService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增商品规格信息查询")
    @ApiOperation("新增商品规格信息查询")
    public ResponseEntity<Object> createViewProductSkuShop(@Validated @RequestBody ViewProductSkuShop resources){
        return new ResponseEntity<>(viewProductSkuShopService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改商品规格信息查询")
    @ApiOperation("修改商品规格信息查询")
    public ResponseEntity<Object> updateViewProductSkuShop(@Validated @RequestBody ViewProductSkuShop resources){
        viewProductSkuShopService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

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