<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Lead extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'lead_number', 'contact_id', 'assigned_to', 'status', 'priority', 'source',
        'preferred_contact', 'enquiry_date', 'follow_up_date', 'project_type',
        'budget_range', 'expected_start', 'description', 'notes', 'internal_notes',
        'site_address', 'site_suburb', 'site_state', 'site_postcode',
    ];

    protected $casts = [
        'enquiry_date' => 'date',
        'follow_up_date' => 'date',
        'expected_start' => 'date',
    ];

    public function contact() { return $this->belongsTo(Contact::class); }
    public function assignedTo() { return $this->belongsTo(User::class, 'assigned_to'); }
    public function jobs() { return $this->hasMany(Job::class); }

    public function statusColor(): string
    {
        return match((string)$this->status) {
            'converted' => 'green',
            'new' => 'blue',
            'consult_booked' => 'purple',
            'on_hold' => 'yellow',
            'lost' => 'red',
            'sold' => 'green',
            default => 'gray',
        };
    }

    public function statusLabel(): string
    {
        return match((string)$this->status) {
            'new'            => 'New',
            'consult_booked' => 'Consult Booked',
            'on_hold'        => 'On Hold',
            'lost'           => 'Lost',
            'sold'           => 'Sold',
            'converted'      => 'Converted',
            default          => ucfirst($this->status),
        };
    }
}
