import { Body, Controller, Get, Patch, Delete, Post, Param, Query, UseGuards } from '@nestjs/common';
import { ScheduledMessagesService } from './scheduled-messages.service';
import { JwtAuthGuard } from '../../common/guards/jwt.guard';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { Workspace } from '../../common/decorators/workspace.decorator';

@Controller('scheduled-messages')
@UseGuards(JwtAuthGuard)
export class ScheduledMessagesController {
  constructor(private readonly scheduledMessagesService: ScheduledMessagesService) {}

  @Get()
  async list(
    @CurrentUser('userId') userId: string,
    @Workspace('id') wsId: string,
    @Query() query: { status?: string },
  ) {
    return this.scheduledMessagesService.list(userId, wsId, query);
  }

  @Post()
  async create(
    @CurrentUser('userId') userId: string,
    @Workspace('id') wsId: string,
    @Body() dto: any,
  ) {
    return this.scheduledMessagesService.create(userId, wsId, dto);
  }

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

  @Delete(':id')
  async cancel(
    @Param('id') id: string,
    @CurrentUser('userId') userId: string,
    @Workspace('id') wsId: string,
  ) {
    return this.scheduledMessagesService.cancel(id, userId, wsId);
  }
}