import { Body, Controller, Post, Route } from "tsoa";
import { sendWebSocket } from "../services/webSocket";

@Route("/api/v1/org/through-socket")
export class SocketController extends Controller {
  @Post("notify")
  async notify(
    @Body()
    payload: {
      message: string;
      userId?: string | string[];
      roles?: string | string[];
      error?: boolean;
    },
  ) {
    sendWebSocket(
      "socket-notification",
      { success: !payload.error, message: payload.message },
      {
        roles: payload.roles || [],
        userId: payload.userId || [],
      },
    );
  }
}
