import {
  Body,
  Controller,
  Get,
  Param,
  ParseUUIDPipe,
  Patch,
  Post,
} from '@nestjs/common';
import {
  TeamCreateSchema,
  TeamUpdateSchema,
  type TeamCreate,
  type TeamUpdate,
} from '@siop/shared';
import { ZodValidationPipe } from '../common/zod-validation.pipe';
import { RequirePermission } from '../permissions/require-permission.decorator';
import { TeamsService } from './teams.service';

@Controller('teams')
export class TeamsController {
  constructor(private readonly teamsService: TeamsService) {}

  @Get()
  @RequirePermission('PEOPLE_TEAMS', 'view')
  list() {
    return this.teamsService.list();
  }

  @Post()
  @RequirePermission('PEOPLE_TEAMS', 'create')
  create(@Body(new ZodValidationPipe(TeamCreateSchema)) body: TeamCreate) {
    return this.teamsService.create(body);
  }

  @Patch(':id')
  @RequirePermission('PEOPLE_TEAMS', 'edit')
  update(
    @Param('id', ParseUUIDPipe) id: string,
    @Body(new ZodValidationPipe(TeamUpdateSchema)) body: TeamUpdate,
  ) {
    return this.teamsService.update(id, body);
  }
}
