package cn.ysk.cashier.controller.shop;

import cn.ysk.cashier.dto.shop.ShopPrinterDTO;
import cn.ysk.cashier.service.shop.ShopPrinterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 店铺打印机配置
 *
 * @author tankaikai
 * @since 2024-09-24 16:56
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "店铺配置-打印机设置")
@RequestMapping("/api/shop-config/printer")
public class ShopPrinterController {

    private final ShopPrinterService shopPrinterService;

    @GetMapping("page")
    @ApiOperation("分页")
    public ResponseEntity page(@RequestParam Map<String, Object> params) {
        Map<String, Object> page = shopPrinterService.page(params);
        return ResponseEntity.ok().body(page);
    }

    @GetMapping("list")
    @ApiOperation("列表")
    public ResponseEntity list(@RequestParam Map<String, Object> params) {
        List<ShopPrinterDTO> list = shopPrinterService.list(params);
        return ResponseEntity.ok().body(list);
    }

    @GetMapping("{id}")
    @ApiOperation("详情")
    public ResponseEntity get(@PathVariable("id") Integer id) {
        ShopPrinterDTO data = shopPrinterService.get(id);
        return ResponseEntity.ok().body(data);
    }

    @PostMapping
    @ApiOperation("保存")
    public ResponseEntity save(@RequestBody ShopPrinterDTO dto) {
        shopPrinterService.save(dto);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PutMapping
    @ApiOperation("修改")
    public ResponseEntity update(@RequestBody ShopPrinterDTO dto) {
        shopPrinterService.update(dto);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @DeleteMapping("{id}")
    @ApiOperation("删除")
    public ResponseEntity delete(@PathVariable("id") Integer id) {
        shopPrinterService.delete(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PostMapping("update-status")
    @ApiOperation("停用或启用")
    public ResponseEntity updateStatus(@RequestBody ShopPrinterDTO dto) {
        shopPrinterService.updateStatus(dto.getId(), dto.getStatus());
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
