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.zcloud.primeport.api.MkmjServiceI;
import com.zcloud.primeport.dto.MkmjAddCmd;
import com.zcloud.primeport.dto.MkmjPageQry;
import com.zcloud.primeport.dto.MkmjUpdateCmd;
import com.zcloud.primeport.dto.MkmjUpdateStatusCmd;
import com.zcloud.primeport.dto.clientobject.MkmjCO;
import com.zcloud.primeport.dto.clientobject.VehicleMessageCO;
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;

@Api(tags = "门口信息管理表")
@RequestMapping("/${application.gateway}/mkmj")
@RestController
@AllArgsConstructor
public class MkmjController {
    private final MkmjServiceI mkmjService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<MkmjCO> add(@Validated @RequestBody MkmjAddCmd cmd) {
        return mkmjService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/listNoToken")
    public PageResponse<MkmjCO> listNoToken(@RequestBody MkmjPageQry qry) {
        return mkmjService.listPage(qry);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<MkmjCO> page(@RequestBody MkmjPageQry qry) {
        return mkmjService.listPage(qry);
    }

    @ApiOperation("所有数据")
    @GetMapping("/listAll")
    public MultiResponse<MkmjCO> listAll(MkmjPageQry qry) {
        return MultiResponse.of(mkmjService.listAll(qry));
    }

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

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

    @ApiOperation("停用启用")
    @PutMapping("/editStatus")
    public SingleResponse editStatus(@Validated @RequestBody MkmjUpdateStatusCmd mkmjUpdateCmd) {
        MkmjUpdateCmd mkmjUpdateCmd1 = new MkmjUpdateCmd();
        mkmjUpdateCmd1.setId(mkmjUpdateCmd.getId());
        mkmjUpdateCmd1.setMkmjStatus(mkmjUpdateCmd.getMkmjStatus());
        mkmjService.edit(mkmjUpdateCmd1);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody MkmjUpdateCmd mkmjUpdateCmd) {
        mkmjService.edit(mkmjUpdateCmd);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("名称唯一性校验")
    @GetMapping("/check-name")
    public SingleResponse<Map<String, Boolean>> checkName(@RequestParam String mkmjName, @RequestParam(required = false) Long id) {
        Boolean available = mkmjService.checkName(mkmjName, id);
        Map<String, Boolean> result = new HashMap<>();
        result.put("available", available);
        return SingleResponse.of(result);
    }

}

