package com.zcloud.primeport.web;


import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.jjb.saas.framework.auth.model.SSOUser;
import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.primeport.api.VehicleApplyServiceI;
import com.zcloud.primeport.domain.model.VehicleApplyE;
import com.zcloud.primeport.dto.*;
import com.zcloud.primeport.dto.clientobject.FgsVehicleCountCo;
import com.zcloud.primeport.dto.clientobject.VehicleApplyCO;
import com.zcloud.primeport.dto.clientobject.VehicleAuditCO;
import com.zcloud.primeport.dto.clientobject.XgfPersonApplyCO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * web-adapter
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:23
 */
@Api(tags = "车辆申请信息")
@RequestMapping("/${application.gateway}/vehicleApply")
@RestController
@AllArgsConstructor
public class VehicleApplyController {
    private final VehicleApplyServiceI vehicleApplyService;

    @ApiOperation("新增-长期车辆录入")
    @PostMapping("/save")
    public SingleResponse<VehicleApplyE> add(@Validated @RequestBody VehicleApplyAddCmd cmd) {
        return vehicleApplyService.add(cmd);
    }
    @ApiOperation("新增-检查部门车辆录入")
    @PostMapping("/inspectCarSave")
    public Response inspectCarSave(@Validated @RequestBody VehicleApplyInspectAddCmd cmd) {
        vehicleApplyService.inspectCarSave(cmd);
        return Response.buildSuccess();
    }
    @ApiOperation("检查部门车辆修改")
    @PutMapping("/inspectCarEdit")
    public Response inspectCarEdit(@Validated @RequestBody VehicleApplyInspectUpdateCmd cmd) {
        cmd.setRemarks(cmd.getCheckDepartmentName());
        vehicleApplyService.inspectCarEdit(cmd);
        return Response.buildSuccess();
    }
//    @ApiOperation("新增-临时访客")
//    @PostMapping("/saveTemporaryVisitors")
//    public SingleResponse<VehicleApplyCO> saveTemporaryVisitors(@Validated @RequestBody VehicleApplyAddCmd cmd) {
//        return null;
//    }

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<VehicleApplyCO> page(@RequestBody VehicleApplyPageQry qry) {
        return vehicleApplyService.listPage(qry);
    }

    @ApiOperation("股份、相关方、临时车辆审批-详情")
    @GetMapping("/{id}")
    public SingleResponse<VehicleApplyCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(vehicleApplyService.getInfoById(id));
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Response remove(@PathVariable("id") Long id) {
        vehicleApplyService.remove(id);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody VehicleApplyUpdateCmd vehicleApplyUpdateCmd) {
        vehicleApplyService.edit(vehicleApplyUpdateCmd);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("车牌号唯一性校验")
    @GetMapping("/check-licence-no")
    public SingleResponse<Map<String, Object>> checkLicenceNo(@RequestParam String licenceNo,
                                                               @RequestParam(required = false) Long id) {
        Map<String, Object> result = vehicleApplyService.checkLicenceNo(licenceNo, id);
//        Map<String, Boolean> result = new HashMap<>();
//        result.put("available", available);
        return SingleResponse.of(result);
    }
    @ApiOperation("车牌号黑名单校验")
    @GetMapping("/check-licence-no-black")
    public SingleResponse<Map<String, Object>> checkLicenceNoBlack(@RequestParam String licenceNo) {
        Map<String, Object> result = vehicleApplyService.checkLicenceNoBlack(licenceNo);
        return SingleResponse.of(result);
    }

    @ApiOperation("分公司统计")
    @PostMapping("/fgsCount")
    public PageResponse<FgsVehicleCountCo> fgsCount(@RequestParam HashMap<String,String> qry) {
        return vehicleApplyService.fgsCount(qry);
    }

    @ApiOperation("跟据车辆归属查询车辆分页")
    @GetMapping("/getCarByVehicleBelongType")
    public PageResponse<VehicleApplyCO> getCarByVehicleBelongType(VehicleApplyPageQry qry) {
        return vehicleApplyService.getCarByVehicleBelongType(qry);
    }

    @ApiOperation("相关方-车辆授权")
    @PostMapping("/xgfCarAuthorization")
    public Response xgfCarAuthorization(@RequestBody CarAuthCmd cmd) {
        vehicleApplyService.xgfCarAuthorization(cmd);
        return Response.buildSuccess();
    }
}

