import { Controller, Get, Post, Param, Body, UseGuards, Req } from '@nestjs/common';
import { Request } from 'express';
import { IsUUID } from 'class-validator';
import { CraftService } from './craft.service';
import { AuthGuard } from '../auth/guards/auth.guard';
import { User } from '../user/user.entity';

class StartCraftDto {
  @IsUUID()
  recipeId: string;
}

@Controller('craft')
export class CraftController {
  constructor(private readonly craftService: CraftService) {}

  @Get('recipes')
  findRecipes() {
    return this.craftService.findAllRecipes();
  }

  @Post('start')
  @UseGuards(AuthGuard)
  start(@Body() dto: StartCraftDto, @Req() req: Request & { user: User }) {
    return this.craftService.startCraft(dto.recipeId, req.user);
  }

  @Get('active')
  @UseGuards(AuthGuard)
  getActive(@Req() req: Request & { user: User }) {
    return this.craftService.getActiveJob(req.user);
  }

  @Post('collect/:jobId')
  @UseGuards(AuthGuard)
  collect(@Param('jobId') jobId: string, @Req() req: Request & { user: User }) {
    return this.craftService.collectCraft(jobId, req.user);
  }
}
