<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class WhatsAppConfiguration extends Model
{
    protected $table = 'whatsapp_configurations';

    protected $fillable = [
        'provider',
        'api_key',
        'api_secret',
        'phone_number_id',
        'business_account_id',
        'config',
        'is_active',
    ];

    protected $hidden = [
        'api_key',
        'api_secret',
    ];

    protected function casts(): array
    {
        return [
            'config' => 'array',
            'is_active' => 'boolean',
        ];
    }

    /**
     * Get active WhatsApp configuration (singleton)
     */
    public static function getActive(): ?self
    {
        return static::where('is_active', true)->first();
    }
}
