import {
  Controller,
  Post,
  UseInterceptors,
  Body,
  UploadedFile,
} from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { ApiBody, ApiConsumes, ApiTags } from '@nestjs/swagger';
import { FileInterceptor } from '@nestjs/platform-express';
import { UploadDto } from './dto/upload.dto';
import { Public } from 'src/core/guards';
import { StoreFileConfig } from 'src/core/helpers/path/upload-store-path.helper';

@ApiTags('uploads')
@Controller('uploads')
@Public(true)
export class UploadController {
  constructor(private moduleRef: ModuleRef) {}

  @Post()
  @ApiConsumes('multipart/form-data')
  @ApiBody({ type: UploadDto })
  @UseInterceptors(FileInterceptor('file', StoreFileConfig))
  async storeFile(
    @UploadedFile() file: Express.Multer.File,
    @Body() body: UploadDto,
  ): Promise<any> {
    return {
      path: file.path,
      full_path: `${process.env.ASSETS}${file.path}`,
    };
  }
}
