<?php
/*
Plugin Name: Unleash AI
Plugin URI: https://unleashai.co/
Description: Generate Meta Tags in seconds: Unleash AI effortlessly creates meta titles, descriptions, and alt text for your pages/posts and images. Simply click on generate and it will create 3 versions of title, description and alt text, pick the one that you love.
Version: 1.0.0
Author: Unleash AI
License: GPL-2.0+
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: unleashai
Domain Path: /languages
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

require_once plugin_dir_path(__FILE__) . 'include/Admin/UnleashAI.php';

use metakeywordai\Admin\UnleashAI;

function unleash_ai_custom_tables_on_activation() {
    global $wpdb;

    // Create Custom API Tokens Table
    $custom_token_table = $wpdb->prefix . 'custom_api_tokens';
    $charset_collate = $wpdb->get_charset_collate();

    $custom_token_table_sql = "CREATE TABLE $custom_token_table (
        id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
        token VARCHAR(64) NOT NULL,
        username VARCHAR(64) NOT NULL,
        active BIGINT(20) NOT NULL,
        expires BIGINT(20) NOT NULL,
        PRIMARY KEY (id),
        UNIQUE KEY token (token)
       
    ) $charset_collate;";

    // Create AI Alt Tags Table
    $ai_alt_tags_table = $wpdb->prefix . 'ai_alt_tags';
    $ai_alt_tags_table_sql = "CREATE TABLE $ai_alt_tags_table (
        id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
        image_id BIGINT(20) UNSIGNED NOT NULL,
        page_id BIGINT(20) UNSIGNED NOT NULL,
        alt_text TEXT NOT NULL,
        PRIMARY KEY (id),
        UNIQUE KEY unique_image_page (image_id, page_id)
    ) $charset_collate;";

    // Include the WordPress upgrade library
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');

    // Execute SQL queries
    dbDelta($custom_token_table_sql);
    dbDelta($ai_alt_tags_table_sql);
}

// Register activation hook
register_activation_hook(__FILE__, 'unleash_ai_custom_tables_on_activation');

new UnleashAI();
