import { Controller, Get, Query, UseGuards } from "@nestjs/common";
import { ApiKeyGuard } from "../auth/api-key.guard";
import { MessagesService } from "./messages.service";

@UseGuards(ApiKeyGuard)
@Controller()
export class MessagesController {
  constructor(private readonly messages: MessagesService) {}

  @Get("messages")
  list(
    @Query("usuarioId") usuarioId?: string,
    @Query("scope") scope?: string,
    @Query("chatId") chatId?: string,
    @Query("from") from?: string,
    @Query("to") to?: string,
    @Query("limit") limit?: string,
    @Query("offset") offset?: string,
  ) {
    return this.messages.listMessages({
      usuarioId,
      scopeAll: scope === "all",
      chatId,
      from,
      to,
      limit: limit ? parseInt(limit, 10) : undefined,
      offset: offset ? parseInt(offset, 10) : undefined,
    });
  }

  @Get("chats")
  chats(
    @Query("usuarioId") usuarioId?: string,
    @Query("scope") scope?: string,
  ) {
    return this.messages.listChats({
      usuarioId,
      scopeAll: scope === "all",
    });
  }
}
