<?php

namespace App\Modules\Admin\Tenancy\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Admin\Tenancy\Models\Tenant;
use App\Modules\Admin\Tenancy\Requests\TenantLifecycleActionRequest;
use App\Modules\Admin\Tenancy\Services\TenantLifecycleService;
use Illuminate\Http\RedirectResponse;

class TenantLifecycleController extends Controller
{
    public function suspend(TenantLifecycleActionRequest $request, Tenant $tenant, TenantLifecycleService $lifecycle): RedirectResponse
    {
        $lifecycle->suspend($tenant, $request->user(), (string) $request->validated('reason'));

        return redirect()->route('admin.tenants.edit', $tenant)->with('status', __('tenant_lifecycle.suspended'));
    }

    public function resume(TenantLifecycleActionRequest $request, Tenant $tenant, TenantLifecycleService $lifecycle): RedirectResponse
    {
        $lifecycle->resumeFromSuspension($tenant, $request->user(), (string) $request->validated('reason'));

        return redirect()->route('admin.tenants.edit', $tenant)->with('status', __('tenant_lifecycle.resumed'));
    }

    public function activate(TenantLifecycleActionRequest $request, Tenant $tenant, TenantLifecycleService $lifecycle): RedirectResponse
    {
        $lifecycle->activate($tenant, $request->user(), (string) $request->validated('reason'));

        return redirect()->route('admin.tenants.edit', $tenant)->with('status', __('tenant_lifecycle.activated'));
    }

    public function archive(TenantLifecycleActionRequest $request, Tenant $tenant, TenantLifecycleService $lifecycle): RedirectResponse
    {
        $lifecycle->archive($tenant, $request->user(), (string) $request->validated('reason'));

        return redirect()->route('admin.tenants.edit', $tenant)->with('status', __('tenant_lifecycle.archived'));
    }
}
