<?php
class WhatsAppFactory {
    public static function create(): WhatsAppInterface {
        $db = db();
        $stmt = $db->query("SELECT setting_value FROM wa_config WHERE setting_key='active_provider'");
        $provider = $stmt->fetchColumn() ?: 'wablas';
        
        switch ($provider) {
            case 'baileys':
                require_once __DIR__ . '/BaileysProvider.php';
                return new BaileysProvider();
            case 'wablas':
            default:
                require_once __DIR__ . '/WablasProvider.php';
                return new WablasProvider();
        }
    }
    
    public static function getActiveProvider(): string {
        $db = db();
        $stmt = $db->query("SELECT setting_value FROM wa_config WHERE setting_key='active_provider'");
        return $stmt->fetchColumn() ?: 'wablas';
    }
    
    public static function getAvailableProviders(): array {
        return [
            'wablas' => [
                'name' => 'Wablas (Cloud API)',
                'description' => 'Layanan WhatsApp gateway berbayar',
                'icon' => 'cloud'
            ],
            'baileys' => [
                'name' => 'Baileys (Self Hosted)',
                'description' => 'Gratis, butuh VPS/Node.js server',
                'icon' => 'server'
            ]
        ];
    }
}