import {Controller, Get, Post, Request, UploadedFile, UseGuards, UseInterceptors,} from '@nestjs/common';
import {ApiTags} from '@nestjs/swagger';
import {JwtAuthGuard} from '../../auth/jwt-auth.guard';

import {ConfigService} from '@nestjs/config';
import {FileInterceptor} from '@nestjs/platform-express';
import {AiModelService} from "../../ai-adapter/ai-model.service";

@ApiTags('users resource')
@Controller('api/users')
export class UserController {
  constructor(
    private readonly modelService: AiModelService,
    private configService: ConfigService,
  ) {}

  @Post('/predict')
  @UseInterceptors(FileInterceptor('file'))
  async predict(@UploadedFile() file: Express.Multer.File) {
    await this.modelService.loadModel();
    const predictedClass = await this.modelService.predict(file);
    return { predicted_class: predictedClass };
  }

  @UseGuards(JwtAuthGuard)
  @Get('profile')
  getProfile(@Request() req) {
    return req.user;
  }
}
