package com.zcloud.primeport.web;


import com.zcloud.primeport.api.VehicleDockLogServiceI;
import com.zcloud.primeport.dto.VehicleDockLogAddCmd;
import com.zcloud.primeport.dto.VehicleDockLogPageQry;
import com.zcloud.primeport.dto.VehicleDockLogUpdateCmd;
import com.zcloud.primeport.dto.clientobject.VehicleDockLogCO;
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 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.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * web-adapter
 *
 * @Author dearLin
 * @Date 2026-04-14 14:53:29
 */
@Api(tags = "车辆对接记录")
@RequestMapping("/${application.gateway}/vehicleDockLog")
@RestController
@AllArgsConstructor
public class VehicleDockLogController {
    private final VehicleDockLogServiceI vehicleDockLogService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<VehicleDockLogCO> add(@Validated @RequestBody VehicleDockLogAddCmd cmd) {
        SSOUser ssoUser = AuthContext.getCurrentUser();
        return vehicleDockLogService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<VehicleDockLogCO> page(@RequestBody VehicleDockLogPageQry qry) {
        return vehicleDockLogService.listPage(qry);
    }

    @ApiOperation("所有数据")
    @GetMapping("/listAll")
    public MultiResponse<VehicleDockLogCO> listAll() {
        return MultiResponse.of(new ArrayList<VehicleDockLogCO>());
    }

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

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

    @ApiOperation("删除多个")
    @DeleteMapping("/ids")
    public Response removeBatch(@RequestParam("ids") String ids) {
        List<Long> idsList = Arrays.stream(ids.split(","))
                .map(Long::valueOf)
                .collect(Collectors.toList());
        vehicleDockLogService.removeBatch(idsList);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody VehicleDockLogUpdateCmd vehicleDockLogUpdateCmd) {
        vehicleDockLogService.edit(vehicleDockLogUpdateCmd);
        return SingleResponse.buildSuccess();
    }
}

