<?php

namespace App\Http\Controllers;

use App\Services\AiSuggestionService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class AiSuggestionController extends Controller
{
    public function meals(Request $request, AiSuggestionService $service): JsonResponse
    {
        $result = $service->suggestMeals($request->user());

        if (isset($result['error'])) {
            return response()->json(['error' => $result['error']], 422);
        }

        return response()->json($result);
    }

    public function outfits(Request $request, AiSuggestionService $service): JsonResponse
    {
        $request->validate([
            'occasion' => ['nullable', 'string'],
            'season' => ['nullable', 'string'],
        ]);

        $result = $service->suggestOutfits(
            $request->user(),
            $request->string('occasion')->toString() ?: null,
            $request->string('season')->toString() ?: null,
        );

        if (isset($result['error'])) {
            return response()->json(['error' => $result['error']], 422);
        }

        return response()->json($result);
    }
}
