import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import { AuthGuard } from '../auth/auth.guard.js';
import { TeamsService } from './teams.service.js';

@Controller('api/teams')
@UseGuards(AuthGuard)
export class TeamsController {
  constructor(private readonly teams: TeamsService) {}

  @Get()
  async list() {
    return this.teams.findAll();
  }

  @Get(':teamId')
  async findOne(@Param('teamId') teamId: string) {
    return this.teams.findById(teamId);
  }

  @Get(':teamId/members')
  async listMembers(@Param('teamId') teamId: string) {
    return this.teams.listMembers(teamId);
  }

  @Get(':teamId/members/:userId')
  async checkMembership(@Param('teamId') teamId: string, @Param('userId') userId: string) {
    const isMember = await this.teams.isMember(teamId, userId);
    return { isMember };
  }
}
