<?php

namespace App\Modules\Settings\Rbac\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Settings\Rbac\Requests\AcceptInvitationRequest;
use App\Modules\Settings\Rbac\Services\TenantUserInviteService;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;

class InvitationAcceptController extends Controller
{
    public function __construct(
        private readonly TenantUserInviteService $invites,
    ) {}

    public function show(string $token): View
    {
        return view('pages.settings.users.accept-invite', [
            'token' => $token,
        ]);
    }

    public function store(AcceptInvitationRequest $request, string $token): RedirectResponse
    {
        $this->invites->accept($token, (string) $request->validated('password'));

        return redirect()->route('login')->with('status', __('rbac.flash.password_set'));
    }
}
