<?php if ( ! defined( 'ABSPATH' ) ) exit; ?>
<?php
class CopulooInitiateTablesClass
{
  function initiate_tables()
  {
    global $wpdb;

    // Create phone details table
    $charset_collate = $wpdb->get_charset_collate();
    $table_prefix = $wpdb->prefix;

    $sql = "CREATE TABLE " . $table_prefix."copuloo_phone_details" . " (
      id varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL UNIQUE,
      user varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      managed_number_code varchar(255) COLLATE utf8mb4_unicode_ci,
      managed_number varchar(255) COLLATE utf8mb4_unicode_ci,
      sid varchar(255) COLLATE utf8mb4_unicode_ci,
      status varchar(255) COLLATE utf8mb4_unicode_ci,
      call1 varchar(255) COLLATE utf8mb4_unicode_ci,
      call2 varchar(255) COLLATE utf8mb4_unicode_ci,
      call3 varchar(255) COLLATE utf8mb4_unicode_ci,
      call1_verified bool COLLATE utf8mb4_unicode_ci,
      call2_verified bool COLLATE utf8mb4_unicode_ci,
      call3_verified bool COLLATE utf8mb4_unicode_ci,
      timezone varchar(255) COLLATE utf8mb4_unicode_ci,
      business_hours text COLLATE utf8mb4_unicode_ci,
      welcome text COLLATE utf8mb4_unicode_ci,
      busy text COLLATE utf8mb4_unicode_ci,
      outside_hours_message text COLLATE utf8mb4_unicode_ci,
      voice_assistant text COLLATE utf8mb4_unicode_ci,
      messages_assistant text COLLATE utf8mb4_unicode_ci,
      web_token text COLLATE utf8mb4_unicode_ci,
      token_created timestamp NULL DEFAULT NULL,
      created_at timestamp NULL DEFAULT NULL,
      updated_at timestamp NULL DEFAULT NULL
    ) $charset_collate;";

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

    // Create released phone numbers table
    $charset_collate = $wpdb->get_charset_collate();
    $table_prefix = $wpdb->prefix;

    $sql = "CREATE TABLE " . $table_prefix."copuloo_released_numbers" . " (
      id varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL UNIQUE,
      user varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      countrycode varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      phone varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      sid varchar(255) COLLATE utf8mb4_unicode_ci,
      location varchar(255) COLLATE utf8mb4_unicode_ci,
      type varchar(255) COLLATE utf8mb4_unicode_ci,
      status varchar(255) COLLATE utf8mb4_unicode_ci,
      created_at timestamp NULL DEFAULT NULL,
      updated_at timestamp NULL DEFAULT NULL
    ) $charset_collate;";

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

    // Create contacts table
    $charset_collate = $wpdb->get_charset_collate();
    $table_prefix = $wpdb->prefix;

    $sql = "CREATE TABLE " . $table_prefix."copuloo_contacts" . " (
      id varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL UNIQUE,
      user varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      name varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      countrycode varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      phone varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      email varchar(255) COLLATE utf8mb4_unicode_ci,
      status varchar(255) COLLATE utf8mb4_unicode_ci,
      statuscolor varchar(255) COLLATE utf8mb4_unicode_ci,
      company varchar(255) COLLATE utf8mb4_unicode_ci,
      icon varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      notes text COLLATE utf8mb4_unicode_ci,
      blocked bool COLLATE utf8mb4_unicode_ci NOT NULL,
      created_at timestamp NULL DEFAULT NULL,
      updated_at timestamp NULL DEFAULT NULL
    ) $charset_collate;";

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

    // Create messages table
    $charset_collate = $wpdb->get_charset_collate();
    $table_prefix = $wpdb->prefix;

    $sql = "CREATE TABLE " . $table_prefix."copuloo_messages" . " (
      id varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL UNIQUE,
      user varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      from_countrycode varchar(255) COLLATE utf8mb4_unicode_ci,
      from_number varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      to_countrycode varchar(255) COLLATE utf8mb4_unicode_ci,
      to_number varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      message text COLLATE utf8mb4_unicode_ci,
      reading bool COLLATE utf8mb4_unicode_ci NOT NULL,
      created_at timestamp NULL DEFAULT NULL
    ) $charset_collate;";

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

    // Create recent calls table
    $charset_collate = $wpdb->get_charset_collate();
    $table_prefix = $wpdb->prefix;

    $sql = "CREATE TABLE " . $table_prefix."copuloo_recents" . " (
      id varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL UNIQUE,
      callsid varchar(255) COLLATE utf8mb4_unicode_ci,
      user varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      from_countrycode varchar(255) COLLATE utf8mb4_unicode_ci,
      from_number varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      to_countrycode varchar(255) COLLATE utf8mb4_unicode_ci,
      to_number varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
      created_at timestamp NULL DEFAULT NULL
    ) $charset_collate;";

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

    // Create API keys table
    $charset_collate = $wpdb->get_charset_collate();
    $table_prefix = $wpdb->prefix;

    $sql = "CREATE TABLE " . $table_prefix."copuloo_api_keys" . " (
      id varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL UNIQUE,
      twilio_sid text COLLATE utf8mb4_unicode_ci,
      twilio_token text COLLATE utf8mb4_unicode_ci,
      TwiML_App_SID text COLLATE utf8mb4_unicode_ci,
      API_KEY text COLLATE utf8mb4_unicode_ci,
      API_SECRET text COLLATE utf8mb4_unicode_ci,
      license_key text COLLATE utf8mb4_unicode_ci,
      additional_info text COLLATE utf8mb4_unicode_ci,
      created_at timestamp NULL DEFAULT NULL,
      updated_at timestamp NULL DEFAULT NULL,
      PRIMARY KEY  (id)
    ) $charset_collate;";

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

    // Create Addresses table
    //$charset_collate = $wpdb->get_charset_collate();
    //$table_prefix = $wpdb->prefix;
    //$sql = "CREATE TABLE " . $table_prefix."copuloo_addresses" . " (
    //  id varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL UNIQUE,
     // user varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
     // twilio_address_sid varchar(255) COLLATE utf8mb4_unicode_ci,
     // friendly_name varchar(255) COLLATE utf8mb4_unicode_ci,
     // country varchar(255) COLLATE utf8mb4_unicode_ci,
     // customer varchar(255) COLLATE utf8mb4_unicode_ci,
     // line1 varchar(255) COLLATE utf8mb4_unicode_ci,
     // line2 varchar(255) COLLATE utf8mb4_unicode_ci,
     //city varchar(255) COLLATE utf8mb4_unicode_ci,
     // state varchar(255) COLLATE utf8mb4_unicode_ci,
     // zip varchar(255) COLLATE utf8mb4_unicode_ci,
     // validated varchar(255) COLLATE utf8mb4_unicode_ci,
     // emergency varchar(255) COLLATE utf8mb4_unicode_ci,
     // created_at timestamp NULL DEFAULT NULL,
     // updated_at timestamp NULL DEFAULT NULL
    //) $charset_collate;";
    //require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    //dbDelta($sql);
  }
}
 ?>
