<?php

namespace App\Http\Controllers\Tenant;

use App\Http\Controllers\Controller;
use App\Services\TenantOnboardingService;
use Illuminate\Http\Request;

class OnboardingController extends Controller
{
    public function welcome(TenantOnboardingService $onboardingService)
    {
        $tenant = auth()->user()->tenant;
        $progress = $onboardingService->getProgress($tenant);

        return view('tenant.onboarding.welcome', compact('tenant', 'progress'));
    }

    public function wizard(TenantOnboardingService $onboardingService)
    {
        $tenant = auth()->user()->tenant;
        $progress = $onboardingService->getProgress($tenant);

        return view('tenant.onboarding.wizard', compact('tenant', 'progress'));
    }

    public function goLive(Request $request, TenantOnboardingService $onboardingService)
    {
        $tenant = auth()->user()->tenant;
        $progress = $onboardingService->getProgress($tenant);

        if (! $progress['is_ready_for_go_live']) {
            return back()->withErrors(['onboarding' => 'Please complete all mandatory setup items before activating Go-Live.']);
        }

        $onboardingService->completeOnboarding($tenant);

        return redirect()->route('app.dashboard')->with('status', '🎉 Congratulations! Your Typing Center ERP workspace is officially LIVE!');
    }
}
