<?php

namespace App\Enums;

enum BookingStatus: string
{
    case NOT_CONTACTED = 'not_contacted';
    case PENDING = 'pending';
    case NOT_APPROVED = 'not_approved';
    case CONTACTED = 'contacted';
    case NEGOTIATING = 'negotiating';
    case CONFIRMED = 'confirmed';
    case COMPLETED = 'completed';
    case CANCELLED = 'cancelled';

    public function label(): string
    {
        return match ($this) {
            self::NOT_CONTACTED => 'Chưa duyệt',
            self::PENDING => 'Đã duyệt',
            self::NOT_APPROVED => 'Không duyệt',
            self::CONTACTED => 'Đã liên hệ',
            self::NEGOTIATING => 'Đang đàm phán',
            self::CONFIRMED => 'Đã xác nhận',
            self::COMPLETED => 'Hoàn thành',
            self::CANCELLED => 'Đã hủy',
        };
    }

    public function kocLabel(): string
    {
        return match ($this) {
            self::NOT_CONTACTED => 'Chưa duyệt',
            self::PENDING => 'Đã duyệt',
            self::NOT_APPROVED => 'Không duyệt',
            self::NEGOTIATING => 'Đang deal',
            self::CONFIRMED => 'Đã chốt',
            self::COMPLETED => 'Đã gửi hàng',
            default => $this->label(),
        };
    }

    public function cssClass(): string
    {
        return 'status-badge--' . $this->value;
    }

    public function timestampField(): ?string
    {
        return match ($this) {
            self::NEGOTIATING => 'negotiating_at',
            self::CONFIRMED => 'confirmed_at',
            self::COMPLETED => 'completed_at',
            default => null,
        };
    }

    public static function values(): array
    {
        return array_column(self::cases(), 'value');
    }

    public static function kocValues(): array
    {
        return array_map(fn($case) => $case->value, self::kocCases());
    }

    public static function default(): self
    {
        return self::NOT_CONTACTED;
    }

    public static function options(): array
    {
        return array_map(fn($case) => [
            'value' => $case->value,
            'label' => $case->label(),
            'cssClass' => $case->cssClass(),
        ], self::cases());
    }

    public static function kocOptions(): array
    {
        return array_map(fn($case) => [
            'value' => $case->value,
            'label' => $case->kocLabel(),
            'cssClass' => $case->cssClass(),
        ], self::kocCases());
    }

    public static function kocOrder(): array
    {
        return [
            self::NOT_CONTACTED->value,
            self::PENDING->value,
            self::NEGOTIATING->value,
            self::CONFIRMED->value,
            self::COMPLETED->value,
        ];
    }

    private static function kocCases(): array
    {
        return [
            self::NOT_CONTACTED,
            self::PENDING,
            self::NOT_APPROVED,
            self::NEGOTIATING,
            self::CONFIRMED,
            self::COMPLETED,
        ];
    }
}
