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.MkmjGateServiceI;
import com.zcloud.primeport.dto.MkmjGateAddCmd;
import com.zcloud.primeport.dto.MkmjGatePageQry;
import com.zcloud.primeport.dto.MkmjGateUpdateCmd;
import com.zcloud.primeport.dto.clientobject.MkmjGateCO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * web-adapter
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:17
 */
@Api(tags = "门口闸机表")
@RequestMapping("/${application.gateway}/mkmjGate")
@RestController
@AllArgsConstructor
public class MkmjGateController {
    private final MkmjGateServiceI mkmjGateService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<MkmjGateCO> add(@Validated @RequestBody MkmjGateAddCmd cmd) {
        return mkmjGateService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<MkmjGateCO> page(@RequestBody MkmjGatePageQry qry) {
        return mkmjGateService.listPage(qry);
    }

    @ApiOperation("详情")
    @GetMapping("/{id}")
    public SingleResponse<MkmjGateCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(mkmjGateService.getInfoById(id));
    }

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

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody MkmjGateUpdateCmd mkmjGateUpdateCmd) {
        mkmjGateService.edit(mkmjGateUpdateCmd);
        return SingleResponse.buildSuccess();
    }
    @ApiOperation("名称唯一性校验")
    @GetMapping("/check-name")
    public SingleResponse<Map<String, Boolean>> checkName(
            @RequestParam String gateName,
            @RequestParam Long passageId,
            @RequestParam(required = false) Long id) {
        Boolean available = mkmjGateService.checkName(gateName, passageId, id);
        Map<String, Boolean> result = new HashMap<>();
        result.put("available", available);
        return SingleResponse.of(result);
    }
}

