<?php

declare(strict_types=1);

namespace App\Support\Onboarding;

enum OnboardingCheckpoint: string
{
    case Identify = 'identify';
    case ConnectProvider = 'connect_provider';
    case VerifyAccess = 'verify_access';
    case Bootstrap = 'bootstrap';
    case CompleteActivate = 'complete_activate';

    public function label(): string
    {
        return match ($this) {
            self::Identify => 'Identify managed environment',
            self::ConnectProvider => 'Connect provider',
            self::VerifyAccess => 'Verify access',
            self::Bootstrap => 'Bootstrap',
            self::CompleteActivate => 'Complete / Activate',
        };
    }

    public function wizardStep(): int
    {
        return match ($this) {
            self::Identify => 1,
            self::ConnectProvider => 2,
            self::VerifyAccess => 3,
            self::Bootstrap => 4,
            self::CompleteActivate => 5,
        };
    }

    public static function fromCurrentStep(?string $step): ?self
    {
        return match ($step) {
            'identify' => self::Identify,
            'connection' => self::ConnectProvider,
            'verify' => self::VerifyAccess,
            'bootstrap' => self::Bootstrap,
            'complete' => self::CompleteActivate,
            default => null,
        };
    }

    /**
     * @return array<int, string>
     */
    public static function values(): array
    {
        return array_map(
            static fn (self $case): string => $case->value,
            self::cases(),
        );
    }
}
