import { Body, Controller, Get, Post, Param, UseGuards } from '@nestjs/common';
import { HuddlesService } from './huddles.service';
import { JwtAuthGuard } from '../../common/guards/jwt.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { Workspace } from '../../common/decorators/workspace.decorator';

@Controller()
@UseGuards(JwtAuthGuard)
export class HuddlesController {
  constructor(private readonly huddlesService: HuddlesService) {}

  @Post('channels/:channelId/huddles')
  async start(
    @Param('channelId') channelId: string,
    @Workspace('id') wsId: string,
    @CurrentUser('userId') userId: string,
    @Body() dto: any,
  ) {
    return this.huddlesService.start(channelId, wsId, userId, dto);
  }

  @Post('huddles/:id/join')
  async join(
    @Param('id') id: string,
    @CurrentUser('userId') userId: string,
    @Body() dto: any,
  ) {
    return this.huddlesService.join(id, userId, dto);
  }

  @Post('huddles/:id/leave')
  async leave(
    @Param('id') id: string,
    @CurrentUser('userId') userId: string,
  ) {
    return this.huddlesService.leave(id, userId);
  }

  @Post('huddles/:id/notes')
  async addNote(
    @Param('id') id: string,
    @Body() dto: any,
  ) {
    return this.huddlesService.addNote(id, dto);
  }

  @Get('huddles/:id')
  async getStatus(@Param('id') id: string) {
    return this.huddlesService.getStatus(id);
  }

  @Post('huddles/:id/end')
  async end(
    @Param('id') id: string,
    @CurrentUser('userId') userId: string,
  ) {
    return this.huddlesService.end(id, userId);
  }

  @Post('huddles/:id/screen-share')
  async toggleScreenShare(
    @Param('id') id: string,
    @CurrentUser('userId') userId: string,
    @Body() dto: { sharing: boolean },
  ) {
    return this.huddlesService.toggleScreenShare(id, userId, dto);
  }

  @Post('huddles/:id/chat')
  async sendChat(
    @Param('id') id: string,
    @CurrentUser('userId') userId: string,
    @Workspace('id') wsId: string,
    @Body() dto: { text: string },
  ) {
    return this.huddlesService.sendChatMessage(id, userId, wsId, dto);
  }

  @Get('huddles/:id/participants')
  async getParticipants(@Param('id') id: string) {
    return this.huddlesService.getActiveParticipants(id);
  }
}