<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Stancl\Tenancy\Database\Concerns\CentralConnection;

/**
 * System-level, publishable blueprint for a CRM lead export. Mirrors
 * ExportMapTemplate: a published template can be applied to a site's LeadExport,
 * seeding its mode / field_map / config. Outbound counterpart of NotificationTemplate.
 */
class LeadExportTemplate extends Model
{
    use CentralConnection;
    use HasFactory;

    protected $fillable = [
        'is_published',
        'title',
        'type',
        'sales_channel',
        'format',
        'mode',
        'field_map',
        'config',
    ];

    protected $casts = [
        'field_map' => 'array',
        'config' => 'array',
        'is_published' => 'bool',
    ];

    public function scopePublished(Builder $query): void
    {
        $query->where('is_published', 1);
    }
}
