<?php
namespace App\Models;

use App\Core\Model;

class Broadcast extends Model {
    protected static string $table = 'broadcasts';

    public static function getWithDetails(): array {
        $stmt = self::db()->query("
            SELECT b.*, wt.name as template_name_title, t.name as target_tag_name, ps.name as target_stage_name
            FROM broadcasts b
            LEFT JOIN whatsapp_templates wt ON b.template_id = wt.id
            LEFT JOIN tags t ON b.target_tag_id = t.id
            LEFT JOIN pipeline_stages ps ON b.target_stage_id = ps.id
            ORDER BY b.created_at DESC
        ");
        return $stmt->fetchAll();
    }
}
