<?php

namespace App\Modules\OrderStatus\Repositories;

use Closure;

class OrderStatusRepository
{
    /**
     * Pending orders are brand new orders that have not been processed yet.
     */
    public const PENDING = 'pending';

    /**
     * Orders that has been registered..
     */
    public const REGISTER = 'register';

    /**
     * Orders that has been registered..
     */
    public const PROCESSING = 'processing';

    /**
     * Orders fulfilled completely.
     */
    public const COMPLETED = 'completed';

    /**
     * Order that has been cancelled.
     */
    public const CANCELLED = 'cancelled';

    /**
     * Mobile device
     */
    public const MOBILE_DEVICE = 'mobile';

    /**
     * Default status value
     */
    public static function defaultStatus(): string
    {
        return static::PENDING;
    }

    /**
     * Status Values
     *
     * @return array<string, string>
     */
    public static function statusValues(): array
    {
        return [
            null => '-',
            self::PENDING => __('Pending'),
            self::REGISTER => __('Registered'),
            self::PROCESSING => __('Processing'),
            self::COMPLETED => __('Completed'),
            self::CANCELLED => __('Cancelled'),
        ];
    }

    /**
     * Tailwind
     *
     * @return array<string, string>
     */
    public static function statusClasses(): array
    {
        return [
            null => '-',
            self::PENDING => 'warning',
            self::REGISTER => 'info',
            self::PROCESSING => 'info',
            self::COMPLETED => 'success',
            self::CANCELLED => 'danger',
        ];
    }

    /**
     * Status icons
     *
     * @return array<string, string>
     */
    public static function statusIcons(): array
    {
        return [
            null => '-',
            'success' => 'check-circle',
            'info' => 'information-circle',
            'primary' => 'clipboard-list',
            'danger' => 'ban',
            'warning' => 'exclamation-circle',
        ];
    }

    /**
     * Status color matching
     */
    public static function statusColorMatching(): Closure
    {
        return fn (string $state): string => match ($state) {
            self::PENDING => 'warning',
            self::REGISTER => 'info',
            self::PROCESSING => 'primary',
            self::COMPLETED => 'success',
            self::CANCELLED => 'danger',
            default => 'primary',
        };
    }

    /**
     * Formatted status for given "status"
     */
    public static function statusFormatted(string $status = 'pending'): string
    {
        return static::statusValues()[$status] ?? __('None');
    }
}
