<?php

namespace App\Http\Controllers\Api\V1;

use App\Http\Controllers\Controller;
use App\Models\TravelPreference;
use Illuminate\Http\Request;

class PreferenceController extends Controller
{
    public function show(Request $request)
    {
        $preference = TravelPreference::where('user_id', $request->user()->id)->first();

        return $this->success($preference);
    }

    public function update(Request $request)
    {
        $data = $request->validate([
            'seat_preference'            => ['sometimes', 'in:aisle,window,none'],
            'meal_type'                  => ['sometimes', 'in:standard,vegetarian,diabetic,other'],
            'meal_notes'                 => ['sometimes', 'nullable', 'string', 'max:500'],
            'roommate_gender_preference' => ['sometimes', 'in:male,female,no_preference'],
            'accessibility_needs'        => ['sometimes', 'nullable', 'string', 'max:1000'],
            'special_requirements'       => ['sometimes', 'nullable', 'string', 'max:1000'],
        ]);

        $preference = TravelPreference::updateOrCreate(
            ['user_id' => $request->user()->id],
            $data
        );

        return $this->success($preference, 'Travel preferences updated.');
    }
}
