<?php

namespace Lucent\Http\Controller;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Lucent\Account\AuthService;
use Lucent\Svelte\Svelte;
use Throwable;
use function Lucent\Response\fail;
use function Lucent\Response\ok;


class AccountController extends Controller
{

    public function __construct(
        public Svelte $svelte,
        public AuthService $authService,
    )
    {
    }

    public function profile()
    {
        return $this->svelte->render(
            layout: "account",
            view: "profile",
            title: "Profile",
        );
    }

    public function updateName(Request $request)
    {

        try {
           $this->authService->updateName($request->input("name"));
        } catch (Throwable $th) {
            return fail($th);
        }

        return ok();
    }

    public function updateEmail(Request $request)
    {

        try {
            $this->authService->updateEmail($request->input("email"));
        } catch (Throwable $th) {
            return fail($th);
        }

        return ok();
    }

}
