<?php

declare(strict_types=1);

namespace App\Support\Baselines;

enum BaselineProfileStatus: string
{
    case Draft = 'draft';
    case Active = 'active';
    case Archived = 'archived';

    public function label(): string
    {
        return match ($this) {
            self::Draft => 'Draft',
            self::Active => 'Active',
            self::Archived => 'Archived',
        };
    }

    /**
     * Filament badge color for this status.
     */
    public function color(): string
    {
        return match ($this) {
            self::Draft => 'gray',
            self::Active => 'success',
            self::Archived => 'warning',
        };
    }

    /**
     * Heroicon identifier for this status.
     */
    public function icon(): string
    {
        return match ($this) {
            self::Draft => 'heroicon-m-pencil-square',
            self::Active => 'heroicon-m-check-circle',
            self::Archived => 'heroicon-m-archive-box',
        };
    }

    /**
     * Whether this status allows editing the profile.
     */
    public function isEditable(): bool
    {
        return $this !== self::Archived;
    }

    /**
     * Allowed transitions from this status.
     *
     * @return array<self>
     */
    public function allowedTransitions(): array
    {
        return match ($this) {
            self::Draft => [self::Draft, self::Active],
            self::Active => [self::Active, self::Archived],
            self::Archived => [self::Archived],
        };
    }

    /**
     * Status options for a Filament Select field, scoped to allowed transitions.
     *
     * @return array<string, string>
     */
    public function selectOptions(): array
    {
        return collect($this->allowedTransitions())
            ->mapWithKeys(fn (self $s): array => [$s->value => $s->label()])
            ->all();
    }
}
