package com.xindazhou.message.controller;

import com.xindazhou.framework.common.pojo.CommonResult;
import com.xindazhou.message.controller.dto.PushRequestDTO;
import com.xindazhou.message.service.PushService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static com.xindazhou.framework.common.pojo.CommonResult.success;

/**
 * 推送控制器
 * 接收 HTTP 推送请求，通过 SocketIO 推送给客户端
 *
 * @author xindazhou
 */
@Slf4j
@Tag(name = "消息推送")
@RestController
@RequestMapping("/push")
@Validated
public class PushController {

    @Resource
    private PushService pushService;

    @PostMapping("/status")
    @Operation(summary = "推送状态更新")
    public CommonResult<Boolean> pushStatus(@Valid @RequestBody PushRequestDTO request) {
        pushService.pushStatusUpdate(request.getUserId(), request.getVehicleId(), request.getData());
        return success(true);
    }

    @PostMapping("/message")
    @Operation(summary = "推送站内信")
    public CommonResult<Boolean> pushMessage(@Valid @RequestBody PushRequestDTO request) {
        pushService.pushInboxMessage(request.getUserId(), request.getData());
        return success(true);
    }

    @PostMapping("/room")
    @Operation(summary = "推送到房间")
    public CommonResult<Boolean> pushToRoom(@RequestParam String room,
                                           @RequestParam String event,
                                           @RequestBody Map<String, Object> data) {
        pushService.pushToRoom(room, event, data);
        return success(true);
    }

    @PostMapping("/user")
    @Operation(summary = "推送给指定用户")
    public CommonResult<Boolean> pushToUser(@RequestParam Long userId,
                                           @RequestParam String event,
                                           @RequestBody Map<String, Object> data) {
        pushService.pushToUser(userId, event, data);
        return success(true);
    }

}

