<?php

declare(strict_types=1);

namespace App\Enums;

/**
 * State of a single custody period in `asset_assignments`.
 *
 * There are only two: an asset is either currently held by an employee, or the
 * custody period has been closed by a recorded return. The database enforces
 * at most one `active` row per asset.
 */
enum AssignmentStatus: string implements HasBadge
{
    case Active = 'active';
    case Returned = 'returned';

    /**
     * @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 => 'Currently Held',
            self::Returned => 'Returned',
        };
    }

    public function color(): string
    {
        return match ($this) {
            self::Active => 'primary',
            self::Returned => 'secondary',
        };
    }

    public function icon(): string
    {
        return match ($this) {
            self::Active => 'person-check',
            self::Returned => 'box-arrow-in-left',
        };
    }
}
