import { Body, Controller, Delete, Get, Param, Post, Query } from '@nestjs/common';
import { MealPlanService } from './meal-plan.service';
import { CreateMealPlanEntryDto } from './dto/create-meal-plan-entry.dto';
import { CurrentUser } from '../auth/decorators/current-user.decorator';

@Controller('meal-plan')
export class MealPlanController {
  constructor(private readonly mealPlanService: MealPlanService) {}

  @Get()
  findByRange(
    @CurrentUser() user: { userId: number },
    @Query('from') from: string,
    @Query('to') to: string,
  ) {
    return this.mealPlanService.findByRange(user.userId, from, to);
  }

  @Get('shopping-list')
  shoppingList(
    @CurrentUser() user: { userId: number },
    @Query('from') from: string,
    @Query('to') to: string,
  ) {
    return this.mealPlanService.shoppingList(user.userId, from, to);
  }

  @Get('inventory-compare')
  inventoryCompare(
    @CurrentUser() user: { userId: number },
    @Query('from') from: string,
    @Query('to') to: string,
  ) {
    return this.mealPlanService.inventoryCompare(user.userId, from, to);
  }

  @Post()
  upsert(
    @CurrentUser() user: { userId: number },
    @Body() dto: CreateMealPlanEntryDto,
  ) {
    return this.mealPlanService.upsert(user.userId, dto);
  }

  @Delete(':date')
  removeByDate(
    @CurrentUser() user: { userId: number },
    @Param('date') date: string,
  ) {
    return this.mealPlanService.removeByDate(user.userId, date);
  }
}
