<?php

namespace App\Domain\Training\Enums;

/** How an applicant fared on a programme (§22). */
enum ParticipationStatus: string
{
    case Registered = 'registered';
    case Attended = 'attended';
    case Absent = 'absent';
    case Passed = 'passed';
    case Failed = 'failed';
    case Withdrawn = 'withdrawn';

    public function label(): string
    {
        return match ($this) {
            self::Registered => 'Registered',
            self::Attended => 'Attended',
            self::Absent => 'Absent',
            self::Passed => 'Passed',
            self::Failed => 'Failed',
            self::Withdrawn => 'Withdrawn',
        };
    }

    /** What the applicant is told; internal grading stays internal. */
    public function publicLabel(): string
    {
        return match ($this) {
            self::Registered => 'Booked',
            self::Attended => 'Attended',
            self::Absent => 'Missed',
            self::Passed => 'Completed',
            self::Failed => 'Needs to be repeated',
            self::Withdrawn => 'Withdrawn',
        };
    }

    /** Only a pass earns a certificate. */
    public function mayHoldCertificate(): bool
    {
        return $this === self::Passed;
    }

    /** Whether this seat still counts against the programme's capacity. */
    public function occupiesSeat(): bool
    {
        return $this !== self::Withdrawn;
    }

    public function isFinal(): bool
    {
        return in_array($this, [self::Passed, self::Failed, self::Absent, self::Withdrawn], true);
    }

    /** @return array<int, string> */
    public static function values(): array
    {
        return array_column(self::cases(), 'value');
    }
}
