import { Controller, Get, Param, Patch, Query, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { CurrentUser } from '../../common/decorators/current-user.decorator';
import { PaginationQueryDto } from '../../common/dto/pagination-query.dto';
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
import { JwtPayload } from '../../common/interfaces/jwt-payload.interface';
import { CollaborationRequestQueryDto } from './dto/collaboration-request-query.dto';
import { CollaborationRequestsService } from './collaboration-requests.service';

@ApiTags('Collaboration Requests')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('collaboration-requests')
export class CollaborationRequestsController {
  constructor(private readonly collaborationRequestsService: CollaborationRequestsService) {}

  @Get()
  async mine(@CurrentUser() user: JwtPayload, @Query() query: PaginationQueryDto) {
    return this.collaborationRequestsService.getMine(user.sub, query);
  }

  @Get('received')
  async received(
    @CurrentUser() user: JwtPayload,
    @Query() query: CollaborationRequestQueryDto,
  ) {
    return this.collaborationRequestsService.listReceived(user.sub, query);
  }

  @Get('sent')
  async sent(@CurrentUser() user: JwtPayload, @Query() query: CollaborationRequestQueryDto) {
    return this.collaborationRequestsService.listSent(user.sub, query);
  }

  @Get(':requestId')
  async getById(@CurrentUser() user: JwtPayload, @Param('requestId') requestId: string) {
    return this.collaborationRequestsService.getById(user.sub, requestId);
  }

  @Patch(':requestId/approve')
  async approve(@CurrentUser() user: JwtPayload, @Param('requestId') requestId: string) {
    return this.collaborationRequestsService.approve(user.sub, requestId);
  }

  @Patch(':requestId/reject')
  async reject(@CurrentUser() user: JwtPayload, @Param('requestId') requestId: string) {
    return this.collaborationRequestsService.reject(user.sub, requestId);
  }

  @Patch(':requestId/cancel')
  async cancel(@CurrentUser() user: JwtPayload, @Param('requestId') requestId: string) {
    return this.collaborationRequestsService.cancel(user.sub, requestId);
  }
}
