import { Body, Controller, Get, Post, Patch, Param, UseGuards } from '@nestjs/common';
import { CanvasService } from './canvas.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 CanvasController {
  constructor(private readonly canvasService: CanvasService) {}

  @Get('channels/:channelId/canvas')
  async listByChannel(@Param('channelId') channelId: string, @Workspace('id') wsId: string) {
    return this.canvasService.listByChannel(channelId, wsId);
  }

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

  @Get('canvas/:id')
  async getById(@Param('id') id: string, @Workspace('id') wsId: string) {
    return this.canvasService.findById(id, wsId);
  }

  @Patch('canvas/:id')
  async update(
    @Param('id') id: string,
    @Workspace('id') wsId: string,
    @CurrentUser('userId') userId: string,
    @Body() dto: any,
  ) {
    return this.canvasService.update(id, wsId, userId, dto);
  }

  @Post('canvas/:id/collaborators')
  async addCollaborator(
    @Param('id') id: string,
    @Workspace('id') wsId: string,
    @Body() dto: any,
  ) {
    return this.canvasService.addCollaborator(id, wsId, dto);
  }
}