<?php

declare(strict_types=1);

namespace App\Http\Controllers\Account;

use App\Http\Controllers\Controller;
use App\Http\Requests\Account\UpdateProfileRequest;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Mtc\MercuryDataModels\Customer;

class ProfileController extends Controller
{
    public function show(Request $request): JsonResponse
    {
        return new JsonResponse([
            'customer' => $request->user('customer'),
        ]);
    }

    public function update(UpdateProfileRequest $request): JsonResponse
    {
        /** @var Customer $customer */
        $customer = Auth::guard('customer')->user();
        $customer->fill($request->validated())->save();

        return new JsonResponse([
            'customer' => $customer->fresh(),
        ]);
    }
}
