<?php

namespace App\Models;

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

class MexcoEnterpriseRequest extends Model
{
    public const STATUS_NEW = 'new';

    public const STATUS_CONTACTED = 'contacted';

    public const STATUS_PROPOSAL = 'proposal';

    public const STATUS_NEGOTIATION = 'negotiation';

    public const STATUS_WON = 'won';

    public const STATUS_LOST = 'lost';

    protected $table = 'mexco_enterprise_requests';

    protected $fillable = [
        'reference_no',
        'organisation_id',
        'organisation_user_id',
        'organisation_name',
        'contact_person',
        'email',
        'phone',
        'event_name',
        'event_date',
        'expected_participants',
        'sessions_count',
        'booths_count',
        'required_features',
        'message',
        'status',
        'assigned_admin_id',
        'contacted_at',
        'closed_at',
        'metadata',
    ];

    protected function casts(): array
    {
        return [
            'event_date' => 'date',
            'required_features' => 'array',
            'contacted_at' => 'datetime',
            'closed_at' => 'datetime',
            'metadata' => 'array',
        ];
    }

    public function organisation(): BelongsTo
    {
        return $this->belongsTo(MexcoOrganisation::class, 'organisation_id');
    }

    public function organisationUser(): BelongsTo
    {
        return $this->belongsTo(MexcoOrganisationUser::class, 'organisation_user_id');
    }

    public function assignee(): BelongsTo
    {
        return $this->belongsTo(MeetupSuperAdmin::class, 'assigned_admin_id');
    }

    public static function statuses(): array
    {
        return [
            self::STATUS_NEW => 'New',
            self::STATUS_CONTACTED => 'Contacted',
            self::STATUS_PROPOSAL => 'Proposal',
            self::STATUS_NEGOTIATION => 'Negotiation',
            self::STATUS_WON => 'Won',
            self::STATUS_LOST => 'Lost',
        ];
    }

    public function statusLabel(): string
    {
        return self::statuses()[$this->status] ?? ucfirst(str_replace('_', ' ', $this->status));
    }
}
