<?php

namespace Digtective\Base;

use Digtective\Repository\TableManagerRepository;

class Activate{
    public static function activate(){
        $charsetCollate = TableManagerRepository::getCharset();
        $prefix = TableManagerRepository::getPrefix();
        $tableName = $prefix . "digtective_token";

        $token_ddl = "CREATE TABLE $tableName (
                id int NOT NULL AUTO_INCREMENT,
                digger_token varchar(9000) NOT NULL,
                PRIMARY KEY (id)
        ) $charsetCollate;";

        $tableExists = TableManagerRepository::tableExists($tableName);

        if(!$tableExists){
            TableManagerRepository::createTable($token_ddl);
        }

        $tableName = $prefix . "digtective_woocommerce_form_submissions";

        $token_ddl = "CREATE TABLE $tableName (
                id int NOT NULL AUTO_INCREMENT,
                form_submission_id varchar(80) NOT NULL,
                order_id int NOT NULL,
                PRIMARY KEY (id)
        ) $charsetCollate;";

        $tableExists = TableManagerRepository::tableExists($tableName);

        if(!$tableExists){
            TableManagerRepository::createTable($token_ddl);
        }

        flush_rewrite_rules();
    }
}
