<?php

namespace App\Http\Controllers\Coach;

use App\Http\Controllers\Controller;
use App\Http\Requests\Coach\ForbiddenFoodRequest;
use App\Http\Requests\Coach\SupplementRequest;
use App\Models\ForbiddenFood;
use App\Models\NutritionPlan;
use App\Models\Supplement;
use App\Services\Coach\NutritionBuilderService;
use Illuminate\Http\RedirectResponse;

class NutritionExtrasController extends Controller
{
    public function __construct(private readonly NutritionBuilderService $builder)
    {
    }

    public function storeForbiddenFood(ForbiddenFoodRequest $request, NutritionPlan $plan): RedirectResponse
    {
        $this->authorize('update', $plan);

        $this->builder->addForbiddenFood($plan, $request->validated());

        return back()->with('status', 'ماده غذایی ممنوع اضافه شد.');
    }

    public function destroyForbiddenFood(ForbiddenFood $food): RedirectResponse
    {
        $this->authorize('update', $food->plan);

        $this->builder->deleteForbiddenFood($food);

        return back()->with('status', 'حذف شد.');
    }

    public function storeSupplement(SupplementRequest $request, NutritionPlan $plan): RedirectResponse
    {
        $this->authorize('update', $plan);

        $this->builder->addSupplement($plan, $request->validated());

        return back()->with('status', 'مکمل اضافه شد.');
    }

    public function destroySupplement(Supplement $supplement): RedirectResponse
    {
        $this->authorize('update', $supplement->plan);

        $this->builder->deleteSupplement($supplement);

        return back()->with('status', 'حذف شد.');
    }
}
