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

@Controller('shared-channels')
@UseGuards(JwtAuthGuard)
export class SharedChannelsController {
  constructor(private readonly sharedChannelsService: SharedChannelsService) {}

  @Get()
  async list(@Workspace('id') wsId: string) {
    return this.sharedChannelsService.list(wsId);
  }

  @Get(':id')
  async getById(@Param('id') id: string) {
    return this.sharedChannelsService.findById(id);
  }

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

  @Post(':id/accept')
  async accept(
    @Param('id') id: string,
    @Workspace('id') wsId: string,
    @CurrentUser('userId') userId: string,
  ) {
    return this.sharedChannelsService.accept(id, wsId, userId);
  }

  @Post(':id/decline')
  async decline(
    @Param('id') id: string,
    @Workspace('id') wsId: string,
  ) {
    return this.sharedChannelsService.decline(id, wsId);
  }

  @Post(':id/disconnect')
  async disconnect(
    @Param('id') id: string,
    @Workspace('id') wsId: string,
  ) {
    return this.sharedChannelsService.disconnect(id, wsId);
  }
}