<?php

defined('ABSPATH') || exit;

class ShopCentral_DB
{
    public static function init()
    {
        self::create_tables();
    }

    public static function create_tables()
    {
        global $wpdb;
        $charset_collate = $wpdb->get_charset_collate();

        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');



        // Stores table
        $table_stores = $wpdb->prefix . 'shopcentral_stores';
        $sql_stores = "CREATE TABLE $table_stores (
            id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
            name varchar(255) NOT NULL,
            url varchar(255) NOT NULL,
            consumer_key varchar(255) NOT NULL,
            consumer_secret varchar(255) NOT NULL,
            is_current tinyint(1) NOT NULL DEFAULT 0,
            maintenance_mode tinyint(1) DEFAULT 0,
            created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
            updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            PRIMARY KEY  (id)
        ) $charset_collate;";
        dbDelta($sql_stores);

        dbDelta($sql_stores);
    }
}