import {
  Controller,
  Get,
  Post,
  Query,
  Res,
  UploadedFiles,
} from '@nestjs/common';
import { Response } from 'express';
import { AppService } from './app.service';
import { logger } from './config';

@Controller()
export class AppController {
  constructor(private readonly service: AppService) {}

  @Get()
  getHello(@Res() res: Response): Response<any, Record<string, any>> {
    return res.json({
      message: 'Wellcome to team management system',
    });
  }

  @Post('/upload')
  async uploadFile(
    @Query('type') type: string = 'multiple',
    @Res() res: Response,
    @UploadedFiles()
    files: {
      files?: Express.Multer.File[];
    },
  ) {
    logger.info('Uploading files');
    const paths = await this.service.uploadFiles(files?.files, type);
    return res
      .json({
        data: paths,
        message: 'Files uploaded successfully',
        status: 200,
      })
      .status(200);
  }
}
