<?php

namespace App\Enums;

enum ApplicationStep: string
{
    case Personal = 'personal';
    case Contact = 'contact';
    case Academic = 'academic';
    case Programme = 'programme';
    case Documents = 'documents';
    case Declaration = 'declaration';
    case Payment = 'payment';
    case Review = 'review';

    public function label(): string
    {
        return match ($this) {
            self::Personal => 'Personal Information',
            self::Contact => 'Contact Information',
            self::Academic => 'Academic History',
            self::Programme => 'Programme Selection',
            self::Documents => 'Documents',
            self::Declaration => 'Declaration',
            self::Payment => 'Payment',
            self::Review => 'Review & Submit',
        };
    }

    public function shortLabel(): string
    {
        return match ($this) {
            self::Personal => 'Personal',
            self::Contact => 'Contact',
            self::Academic => 'Academic',
            self::Programme => 'Programme',
            self::Documents => 'Documents',
            self::Declaration => 'Declaration',
            self::Payment => 'Payment',
            self::Review => 'Submit',
        };
    }

    public function position(): int
    {
        return array_search($this, self::cases(), true) + 1;
    }

    public static function first(): self
    {
        return self::Personal;
    }

    public static function total(): int
    {
        return count(self::cases());
    }

    public function next(): ?self
    {
        $cases = self::cases();
        return $cases[array_search($this, $cases, true) + 1] ?? null;
    }

    public function previous(): ?self
    {
        $index = array_search($this, self::cases(), true);
        return $index > 0 ? self::cases()[$index - 1] : null;
    }
}
