package com.sckw.system.controller;

import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.system.model.vo.req.PrinterPageReqVo;
import com.sckw.system.model.vo.req.PrinterSaveReqVo;
import com.sckw.system.model.vo.req.PrinterStatusReqVo;
import com.sckw.system.service.KwsPrinterManageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 打印机管理控制器。
 */
@RestController
@RequestMapping("/kwsPrinter")
@Tag(name = "打印机管理")
@RequiredArgsConstructor
public class KwsPrinterController {

    private final KwsPrinterManageService kwsPrinterManageService;

    @PostMapping("/page")
    @Operation(summary = "打印机分页查询")
    public HttpResult page(@RequestBody PrinterPageReqVo reqVo) {
        return HttpResult.ok(kwsPrinterManageService.page(reqVo));
    }

    @GetMapping("/detail")
    @Operation(summary = "打印机详情")
    public HttpResult detail(@RequestParam Long id) {
        return HttpResult.ok(kwsPrinterManageService.detail(id));
    }

    @PostMapping("/add")
    @Operation(summary = "新增打印机")
    public HttpResult add(@RequestBody PrinterSaveReqVo reqVo) {
        kwsPrinterManageService.add(reqVo);
        return HttpResult.ok(HttpStatus.MSG_003);
    }

    @PostMapping("/update")
    @Operation(summary = "编辑打印机")
    public HttpResult update(@RequestBody PrinterSaveReqVo reqVo) {
        kwsPrinterManageService.update(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    @PostMapping("/updateStatus")
    @Operation(summary = "启用停用打印机")
    public HttpResult updateStatus(@RequestBody PrinterStatusReqVo reqVo) {
        kwsPrinterManageService.updateStatus(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    @GetMapping("/enterpriseOptions")
    @Operation(summary = "企业模糊搜索")
    public HttpResult enterpriseOptions(@RequestParam(required = false) String keyword) {
        return HttpResult.ok(kwsPrinterManageService.enterpriseOptions(keyword));
    }

    @GetMapping("/optionsByEntId")
    @Operation(summary = "按企业查询打印机下拉")
    public HttpResult optionsByEntId(@RequestParam Long entId) {
        return HttpResult.ok(kwsPrinterManageService.optionByEntId(entId));
    }
}
