<?php

namespace App\Http\Controllers\Api\Profile;

use App\Http\Controllers\Api\BaseController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ProfileController extends BaseController
{
    public function show(Request $request): JsonResponse
    {
        $user = $request->user()->load('wallet');

        return $this->successResponse([
            'user' => $user,
            'wallet_balance' => $user->wallet?->balance ?? 0,
        ]);
    }

    public function update(Request $request): JsonResponse
    {
        $validated = $request->validate([
            'first_name' => ['sometimes', 'string', 'max:255'],
            'last_name' => ['sometimes', 'string', 'max:255'],
            'phone' => ['sometimes', 'nullable', 'string', 'max:20'],
            'timezone' => ['sometimes', 'string', 'max:50'],
            'locale' => ['sometimes', 'string', 'max:10'],
        ]);

        $request->user()->update($validated);

        return $this->successResponse(
            $request->user()->fresh(),
            'Profile updated successfully'
        );
    }
}
