import { Controller, Post, Get, UseInterceptors, UploadedFile } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { PalmOilService } from './palm-oil.service';
import { AnalysisResponse } from './interfaces/palm-analysis.interface';

@Controller('palm-oil')
export class PalmOilController {
  constructor(private readonly palmOilService: PalmOilService) { }

  @Post('analyze')
  @UseInterceptors(FileInterceptor('image'))
  async analyze(@UploadedFile() file: Express.Multer.File): Promise<AnalysisResponse> {
    if (!file) {
      throw new Error('No image uploaded');
    }
    let res = await this.palmOilService.analyzeImage(file.buffer, file.originalname)
    // console.log(res)
    // console.log(res.detections)
    return res;
  }

  @Get('history')
  async getHistory() {
    return this.palmOilService.getHistory();
  }
}
