package com.sckw.system.controller;

import com.sckw.core.utils.TruckNoUtils;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.system.model.vo.req.*;
import com.sckw.system.model.vo.res.LicensePlateValidateResponse;
import com.sckw.system.service.KwsWeighbridgeManageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
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;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;

/**
 * 地磅控制器
 */
@RestController
@RequestMapping("/kwsWeighbridge")
@Tag(name = "地磅管理")
@RequiredArgsConstructor
public class KwsWeighbridgeController {

    private final KwsWeighbridgeManageService kwsWeighbridgeManageService;

    @PostMapping("/page")
    @Operation(summary = "地磅分页查询")
    public HttpResult page(@RequestBody WeighbridgePageReqVo reqVo) {
        return HttpResult.ok(kwsWeighbridgeManageService.page(reqVo));
    }

    @GetMapping("/detail")
    @Operation(summary = "地磅详情")
    public HttpResult detail(@RequestParam Long id) {
        return HttpResult.ok(kwsWeighbridgeManageService.detail(id));
    }

    @PostMapping("/add")
    @Operation(summary = "新增地磅")
    public HttpResult add(@RequestBody WeighbridgeSaveReqVo reqVo) {
        kwsWeighbridgeManageService.add(reqVo);
        return HttpResult.ok(HttpStatus.MSG_003);
    }

    @PostMapping("/update")
    @Operation(summary = "更新地磅")
    public HttpResult update(@RequestBody WeighbridgeSaveReqVo reqVo) {
        kwsWeighbridgeManageService.update(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    @PostMapping("/updateStatus")
    @Operation(summary = "更新地磅状态，停用启用接口")
    public HttpResult updateStatus(@RequestBody WeighbridgeStatusReqVo reqVo) {
        kwsWeighbridgeManageService.updateStatus(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    @PostMapping("/updateDiffConfig")
    @Operation(summary = "保存地磅差值配置")
    public HttpResult updateDiffConfig(@RequestBody WeighbridgeDiffConfigReqVo reqVo) {
        kwsWeighbridgeManageService.updateDiffConfig(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    @GetMapping("/diffConfigDetail")
    @Operation(summary = "获取地磅差值配置详情")
    public HttpResult diffConfigDetail(@RequestParam Long entId) {
        return HttpResult.ok(kwsWeighbridgeManageService.diffConfigDetail(entId));
    }

    @PostMapping("/restart")
    @Operation(summary = "重启地磅")
    public HttpResult restart(@RequestBody WeighbridgeRestartReqVo reqVo) {
        kwsWeighbridgeManageService.restart(reqVo);
        return HttpResult.ok("重启命令已记录");
    }

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

    @GetMapping("/checkUniqueCode")
    @Operation(summary = "检查唯一编码可用性")
    public HttpResult checkUniqueCode(@RequestParam String uniqueCode,
                                      @RequestParam(required = false) Long id) {
        return HttpResult.ok(kwsWeighbridgeManageService.checkUniqueCodeAvailable(uniqueCode, id));
    }

}
