<?php
/**
 * ORM Grammar Factory
 * 
 * @package ZenoChatbot\Framework\Database\ORM\Grammar
 */

namespace ZenoChatbot\Framework\Database\ORM\Grammar;

use ZenoChatbot\Framework\Database\ORM\Connection;

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * ORM Grammar Factory Class
 */
class GrammarFactory
{
    /**
     * Create appropriate grammar instance based on database type
     *
     * @param Connection $connection
     * @return Grammar
     */
    public static function make(Connection $connection)
    {
        switch ($connection->getType()) {
            case 'sqlite':
                return new SqliteGrammar($connection);
            case 'mysql':
            default:
                return new MySqlGrammar($connection);
        }
    }

    /**
     * Get available grammar types
     *
     * @return array
     */
    public static function getAvailableTypes()
    {
        return ['mysql', 'sqlite'];
    }

    /**
     * Check if grammar type is supported
     *
     * @param string $type
     * @return bool
     */
    public static function isSupported($type)
    {
        return in_array(strtolower($type), static::getAvailableTypes());
    }

    /**
     * Create MySQL grammar
     *
     * @param Connection $connection
     * @return MySqlGrammar
     */
    public static function mysql(Connection $connection)
    {
        return new MySqlGrammar($connection);
    }

    /**
     * Create SQLite grammar
     *
     * @param Connection $connection
     * @return SqliteGrammar
     */
    public static function sqlite(Connection $connection)
    {
        return new SqliteGrammar($connection);
    }

    /**
     * Auto-detect and create grammar based on WordPress configuration
     *
     * @return Grammar
     */
    public static function auto()
    {
        $connection = new Connection();
        return static::make($connection);
    }
}
