<?php

namespace App\Domain\Event\Enums;

enum FormFieldType: string
{
    case Text = 'text';
    case Textarea = 'textarea';
    case Number = 'number';
    case Email = 'email';
    case Phone = 'phone';
    case Date = 'date';
    case Select = 'select';
    case MultiSelect = 'multi_select';
    case Radio = 'radio';
    case Checkbox = 'checkbox';
    case FileUpload = 'file_upload';
    case NationalId = 'national_id';
    case Location = 'location';
    case SectionDivider = 'section_divider';
    case Terms = 'terms';

    public function label(): string
    {
        return match ($this) {
            self::Text => 'نص قصير',
            self::Textarea => 'نص طويل',
            self::Number => 'رقم',
            self::Email => 'بريد إلكتروني',
            self::Phone => 'هاتف',
            self::Date => 'تاريخ',
            self::Select => 'قائمة منسدلة (اختيار واحد)',
            self::MultiSelect => 'اختيار متعدد',
            self::Radio => 'أزرار اختيار (إجابة واحدة)',
            self::Checkbox => 'خانة اختيار',
            self::FileUpload => 'رفع ملف',
            self::NationalId => 'الرقم القومي',
            self::Location => 'موقع خريطة',
            self::SectionDivider => 'فاصل / عنوان قسم',
            self::Terms => 'الموافقة على الشروط',
        };
    }

    public function icon(): string
    {
        return match ($this) {
            self::Text => 'bars-3-bottom-left',
            self::Textarea => 'document-text',
            self::Number => 'hashtag',
            self::Email => 'at-symbol',
            self::Phone => 'phone',
            self::Date => 'calendar',
            self::Select => 'chevron-down',
            self::MultiSelect => 'list-bullet',
            self::Radio => 'check-circle',
            self::Checkbox => 'check',
            self::FileUpload => 'arrow-up-tray',
            self::NationalId => 'identification',
            self::Location => 'map-pin',
            self::SectionDivider => 'minus',
            self::Terms => 'shield-check',
        };
    }

    public function baseValidation(): string
    {
        return match ($this) {
            self::Text => 'string|max:500',
            self::Textarea => 'string|max:5000',
            self::Number => 'numeric',
            self::Email => 'email|max:255',
            self::Phone => 'string|max:20',
            self::Date => 'date',
            self::Select => 'string',
            self::MultiSelect => 'array',
            self::Radio => 'string',
            self::Checkbox => 'accepted',
            self::FileUpload => 'file|max:5120',
            self::NationalId => 'string|size:14|regex:/^[0-9]{14}$/',
            self::Location => 'string',
            self::SectionDivider => '',
            self::Terms => 'accepted',
        };
    }

    public function hasOptions(): bool
    {
        return in_array($this, [self::Select, self::MultiSelect, self::Radio]);
    }

    public function isInputField(): bool
    {
        return $this !== self::SectionDivider;
    }

    public function supportsUnique(): bool
    {
        return in_array($this, [self::Text, self::Email, self::Phone, self::NationalId, self::Number]);
    }
}
