<?php

namespace App\Http\Controllers\Admin\Account;

use App\Http\Controllers\Concerns\FlashesEntityMessage;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\Account\UpdatePasswordRequest;
use App\Services\Account\ProfileService;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
use Inertia\Response;

class PasswordController extends Controller
{
    use FlashesEntityMessage;

    public function __construct(
        private readonly ProfileService $profileService,
    ) {}

    public function edit(): Response
    {
        return Inertia::render('admin/account/Password');
    }

    public function update(UpdatePasswordRequest $request): RedirectResponse
    {
        $this->profileService->updatePassword(
            $request->user(),
            $request->validated('password'),
        );

        $this->flashUpdated('Kata sandi');

        return redirect()->route('admin.account.password');
    }
}
