<?php

declare(strict_types=1);

namespace App\Enums;

/**
 * Employment state, from the asset register's point of view.
 *
 * `OnNotice` exists because asset clearance starts at resignation, not at exit.
 * "Employees on notice who still hold assets" is the highest-value alert in the
 * whole system: it prevents the most common and most expensive AMS failure,
 * which is someone leaving with a laptop.
 */
enum EmployeeStatus: string implements HasBadge
{
    case Active = 'active';
    case OnNotice = 'on_notice';
    case Exited = 'exited';
    case Inactive = 'inactive';

    /**
     * @return array<string, string> value => label, for select inputs
     */
    public static function options(): array
    {
        return array_reduce(
            self::cases(),
            static fn (array $carry, self $case): array => $carry + [$case->value => $case->label()],
            [],
        );
    }

    public function label(): string
    {
        return match ($this) {
            self::Active => 'Active',
            self::OnNotice => 'On Notice',
            self::Exited => 'Exited',
            self::Inactive => 'Inactive',
        };
    }

    public function color(): string
    {
        return match ($this) {
            self::Active => 'success',
            self::OnNotice => 'warning',
            self::Exited => 'secondary',
            self::Inactive => 'dark',
        };
    }

    public function icon(): string
    {
        return match ($this) {
            self::Active => 'person-check',
            self::OnNotice => 'hourglass-split',
            self::Exited => 'box-arrow-right',
            self::Inactive => 'person-dash',
        };
    }

    /**
     * An exited employee must never be issued another asset.
     */
    public function canReceiveAssets(): bool
    {
        return $this === self::Active || $this === self::OnNotice;
    }

    /**
     * Whether outstanding assets held by this employee should be chased.
     */
    public function requiresClearance(): bool
    {
        return $this === self::OnNotice || $this === self::Exited;
    }
}
