<?php

declare(strict_types=1);

namespace App\Models;

use App\Core\BaseModel;

final class LeadSourceModel extends BaseModel
{
    protected string $table = 'lead_sources';
    protected array $fillable = ['name', 'slug', 'is_active', 'sort_order'];
    protected bool $timestamps = false;
    protected bool $softDeletes = false;
    protected bool $auditStamps = false;

    public function allWithLeadCounts(): array
    {
        return $this->db->query(
            "SELECT s.*, COUNT(l.id) AS lead_count
             FROM lead_sources s
             LEFT JOIN leads l ON l.lead_source_id = s.id AND l.deleted_at IS NULL
             GROUP BY s.id
             ORDER BY s.sort_order"
        )->fetchAll();
    }
}
