<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ConsultationRequest extends Model
{
    protected $guarded = ['id', 'created_at', 'updated_at'];

    protected $casts = [
        'provider_can_visit' => 'boolean',
        'closed_at' => 'datetime',
    ];

    public const STATUS_PENDING = 'pending';
    public const STATUS_APPROVED = 'approved';
    public const STATUS_REJECTED = 'rejected';
    public const STATUS_CLOSED = 'closed';

    public const PRIORITY_LOW = 'low';
    public const PRIORITY_NORMAL = 'normal';
    public const PRIORITY_URGENT = 'urgent';
    public const PRIORITY_EMERGENCY = 'emergency';

    public const TYPE_FEED = 'feed';
    public const TYPE_HERD = 'herd';
    public const TYPE_OTHER = 'other';

    public const FORMAT_IN_PERSON = 'in_person';
    public const FORMAT_ONLINE = 'online';

    public static function statusOptions(): array
    {
        return [
            self::STATUS_PENDING => 'انتظار',
            self::STATUS_APPROVED => 'تایید',
            self::STATUS_REJECTED => 'رد',
            self::STATUS_CLOSED => 'بسته',
        ];
    }

    public static function priorityOptions(): array
    {
        return [
            self::PRIORITY_LOW => 'غیرضروری',
            self::PRIORITY_NORMAL => 'متوسط',
            self::PRIORITY_URGENT => 'فوری',
            self::PRIORITY_EMERGENCY => 'اورژانسی',
        ];
    }

    public static function typeOptions(): array
    {
        return [
            self::TYPE_FEED => 'خوراک',
            self::TYPE_HERD => 'مدیریت گله',
            self::TYPE_OTHER => 'سایر تخصصی',
        ];
    }

    public static function formatOptions(): array
    {
        return [
            self::FORMAT_IN_PERSON => 'حضوری',
            self::FORMAT_ONLINE => 'آنلاین',
        ];
    }

    public function producer(): BelongsTo
    {
        return $this->belongsTo(Producer::class);
    }

    public function expert(): BelongsTo
    {
        return $this->belongsTo(Expert::class);
    }

    public function closedByUser(): BelongsTo
    {
        return $this->belongsTo(User::class, 'closed_by');
    }
}
