<?php

namespace App\Enums;

use App\Traits\ProvidesEnumOptions;
use InvalidArgumentException;

enum CuttingStatus: string
{
    use ProvidesEnumOptions;

    case IN_PROGRESS = 'in_progress';
    case COMPLETED = 'completed';

    public function label(): string
    {
        return match ($this) {
            self::IN_PROGRESS => 'Proses',
            self::COMPLETED => 'Selesai',
        };
    }

    public function isEditable(): bool
    {
        return $this === self::IN_PROGRESS;
    }

    public function transitionStatusMessage(): string
    {
        return match ($this) {
            self::COMPLETED => 'Proses cutting berhasil diselesaikan.',
            default => 'Status proses cutting berhasil diperbarui.',
        };
    }

    public function canTransitionTo(self $status): bool
    {
        return match ($this) {
            self::IN_PROGRESS => $status === self::COMPLETED,
            default => false,
        };
    }

    public function transitionPermission(): Permission
    {
        return match ($this) {
            self::COMPLETED => Permission::CUTTINGS_COMPLETE,
            self::IN_PROGRESS => Permission::CUTTINGS_UPDATE,
            default => throw new InvalidArgumentException('Status tidak mendukung transisi.'),
        };
    }

    /**
     * @return list<array{status: string, label: string, destructive: bool, permission: string, icon_only: bool}>
     */
    public function availableActions(): array
    {
        return match ($this) {
            self::IN_PROGRESS => [
                [
                    'status' => self::COMPLETED->value,
                    'label' => 'Selesai',
                    'destructive' => false,
                    'permission' => Permission::CUTTINGS_COMPLETE->value,
                    'icon_only' => false,
                ],
            ],
            default => [],
        };
    }
}
