<?php

declare(strict_types=1);

namespace App\Http\Controllers\Academy;

use App\Http\Controllers\Controller;
use App\Support\AcademyAnalytics\AcademyAnalyticsContentType;
use App\Support\Seo\SeoFactory;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

final class AcademyPricingController extends Controller
{
    public function index(Request $request): Response
    {
        abort_unless((bool) config('academy.enabled', true), 404);

        $canonical = route('academy.pricing');
        $seo = app(SeoFactory::class)
            ->collectionPage(
                'Skinbase AI Academy Pricing — Skinbase',
                'Compare Skinbase AI Academy Explorer, Creator, and Pro plans and preview premium access before payments go live.',
                $canonical,
            )
            ->toArray();

        $seo['og_type'] = 'website';

        return Inertia::render('Academy/Pricing', [
            'seo' => $seo,
            'paymentsEnabled' => (bool) config('academy.payments_enabled', false),
            'plans' => [
                [
                    'name' => 'Explorer',
                    'price' => '€0',
                    'interval' => '/ month',
                    'badge' => 'Free',
                    'features' => [
                        'Beginner AI lessons',
                        'Basic prompting tutorials',
                        'Public prompt previews',
                        'Public Academy challenges',
                    ],
                ],
                [
                    'name' => 'Creator',
                    'price' => '€4.99',
                    'interval' => '/ month',
                    'badge' => 'Premium',
                    'features' => [
                        'Full prompt library',
                        'Premium lessons',
                        'Prompt packs',
                        'Saved prompt collections',
                    ],
                ],
                [
                    'name' => 'Pro',
                    'price' => '€9.99',
                    'interval' => '/ month',
                    'badge' => 'Advanced',
                    'features' => [
                        'Advanced AI workflows',
                        'World Builder kits',
                        'Pro challenges',
                        'Profile highlight badge',
                    ],
                ],
            ],
            'analytics' => [
                'enabled' => true,
                'contentType' => AcademyAnalyticsContentType::UPGRADE,
                'contentId' => null,
                'eventUrl' => route('academy.analytics.events.store'),
                'pageName' => 'academy_pricing',
                'isPremium' => false,
                'isGuest' => $request->user() === null,
                'isSubscriber' => $request->user()?->hasAcademyCreatorAccess() || $request->user()?->hasAcademyProAccess(),
            ],
        ])->rootView('collections');
    }
}