<?php

namespace Modules\Bms\Entities;

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

class BmsLead extends Model
{
    protected $table = 'bms_leads';

    public const STAGES = [
        'wizard_incomplete',
        'wizard_complete',
        'qualified_awaiting_contact',
        'contacted',
        'proposal_sent',
        'negotiation',
        'won',
        'lost',
    ];

    protected $fillable = [
        'business_id', 'contact_id', 'whatsapp', 'wizard_session_id', 'stage', 'source',
        'assigned_to', 'event_type', 'attendees', 'fnb_level', 'venue_preference',
        'budget_min', 'budget_max', 'candidate_dates', 'area_id', 'notes',
        'last_activity_at',
    ];

    protected $casts = [
        'attendees'        => 'integer',
        'budget_min'       => 'decimal:2',
        'budget_max'       => 'decimal:2',
        'candidate_dates'  => 'array',
        'last_activity_at' => 'datetime',
    ];

    public function contact(): BelongsTo
    {
        return $this->belongsTo(\App\Contact::class, 'contact_id');
    }

    public function wizardSession(): BelongsTo
    {
        return $this->belongsTo(BmsWizardSession::class, 'wizard_session_id');
    }

    public function area(): BelongsTo
    {
        return $this->belongsTo(BmsArea::class, 'area_id');
    }

    public function selectedHalls(): HasMany
    {
        return $this->hasMany(BmsLeadHall::class, 'lead_id');
    }

    public function bookings(): HasMany
    {
        return $this->hasMany(BmsBooking::class, 'lead_id');
    }
}
