package com.xindazhou.business.controller.admin.vehicle;

import com.xindazhou.framework.common.pojo.CommonResult;
import com.xindazhou.vehicle.api.VehicleAlarmApi;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 管理后台 - 车辆报警 Controller
 * 
 * 接收前端请求，通过 Feign 调用车辆服务
 *
 * @author xindazhou
 */
@Tag(name = "管理后台 - 车辆报警")
@RestController
@RequestMapping("/vehicle/alarm")
@Validated
public class VehicleAlarmController {

    @Resource
    private VehicleAlarmApi vehicleAlarmApi;

    /**
     * 推送报警通知（测试用）
     * 
     * 流程：管理后台 → 业务服务 → 车辆服务 → Redis MQ → 消息服务 → SocketIO → 客户端
     */
    @PostMapping("/push")
    @Operation(summary = "推送报警通知（测试用）", 
               description = "测试报警推送功能。流程：管理后台 → 业务服务 → 车辆服务 → Redis MQ → 消息服务 → SocketIO → 客户端")
    @Parameter(name = "userId", description = "用户ID", required = true, example = "1")
    @Parameter(name = "vehicleId", description = "车辆ID", required = true, example = "1")
    @Parameter(name = "alarmType", description = "报警类型", required = false, example = "test_alarm")
    public CommonResult<Boolean> pushAlarm(@RequestParam("userId") Long userId,
                                           @RequestParam("vehicleId") Long vehicleId,
                                           @RequestParam(value = "alarmType", required = false, defaultValue = "test_alarm") String alarmType,
                                           @RequestBody(required = false) Map<String, Object> alarmData) {
        // 通过 Feign 调用车辆服务
        return vehicleAlarmApi.pushAlarm(userId, vehicleId, alarmType, alarmData);
    }

}

