import {
  Body,
  Controller,
  Get,
  NotImplementedException,
  Param,
  Post,
} from '@nestjs/common';
import {
  ApiCreatedResponse,
  ApiOkResponse,
  ApiOperation,
  ApiTags,
} from '@nestjs/swagger';
import {
  UploadFinalizeResponseDto,
  UploadPrepareRequestDto,
  UploadPrepareResponseDto,
  UploadSessionStatusResponseDto,
} from './uploads.dto';
import { UploadsService } from './uploads.service';

@ApiTags('uploads')
@Controller({
  path: 'uploads',
  version: '1',
})
export class UploadsController {
  constructor(private readonly uploadsService: UploadsService) {}

  @Post('prepare')
  @ApiCreatedResponse({ type: UploadPrepareResponseDto })
  async prepare(
    @Body() body: UploadPrepareRequestDto,
  ): Promise<UploadPrepareResponseDto> {
    return this.uploadsService.prepare(body);
  }

  @Get(':uploadId')
  @ApiOkResponse({ type: UploadSessionStatusResponseDto })
  async getStatus(
    @Param('uploadId') uploadId: string,
  ): Promise<UploadSessionStatusResponseDto> {
    return this.uploadsService.getStatus(uploadId);
  }

  @Post(':uploadId/finalize')
  @ApiOperation({ summary: 'Reserved for the next milestone' })
  @ApiOkResponse({ type: UploadFinalizeResponseDto })
  async finalize(): Promise<UploadFinalizeResponseDto> {
    throw new NotImplementedException('Upload finalization is not implemented yet.');
  }
}
