<?php

namespace App\Http\Controllers\Api;

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

class ProfileController extends Controller
{
    public function getProfile(Request $request)
    {
        return response()->json(['success' => true, 'user' => $request->user()]);
    }

    public function getPreferences(Request $request)
    {
        $prefs = UserPreference::firstOrCreate(['user_id' => $request->user()->id]);
        return response()->json(['success' => true, 'preferences' => $prefs]);
    }

    public function updatePreferences(Request $request)
    {
        $prefs = UserPreference::firstOrCreate(['user_id' => $request->user()->id]);
        $prefs->update($request->all());
        return response()->json(['success' => true, 'message' => 'Preferences updated', 'preferences' => $prefs]);
    }

    public function updateProfile(Request $request)
    {
        $user = $request->user();
        $user->update($request->only('name', 'email', 'phone'));
        return response()->json(['success' => true, 'message' => 'Profile updated successfully']);
    }
}
