<?php
use Index\Data\IDbConnection;
use Index\Data\Migration\IDbMigration;

final class UpdateCollationsInVariousTables_20230803_114403 implements IDbMigration {
    public function migrate(IDbConnection $conn): void {
        $conn->execute('
            ALTER TABLE msz_audit_log
                CHANGE COLUMN log_action  log_action  VARCHAR(50) NOT NULL              COLLATE "ascii_general_ci" AFTER user_id,
                CHANGE COLUMN log_country log_country CHAR(2)     NOT NULL DEFAULT "XX" COLLATE "ascii_general_ci" AFTER log_ip;
        ');

        $conn->execute('
            ALTER TABLE msz_auth_tfa
                CHANGE COLUMN tfa_token tfa_token CHAR(32) NOT NULL COLLATE "ascii_bin" AFTER user_id;
        ');

        $conn->execute('
            ALTER TABLE msz_changelog_changes
                CHANGE COLUMN change_log  change_log  VARCHAR(255) NOT NULL          COLLATE "utf8mb4_unicode_520_ci" AFTER change_created,
                CHANGE COLUMN change_text change_text TEXT         NULL DEFAULT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER change_log;
        ');

        $conn->execute('
            ALTER TABLE msz_changelog_tags
                CHANGE COLUMN tag_name        tag_name        VARCHAR(255) NOT NULL          COLLATE "utf8mb4_unicode_520_ci" AFTER tag_id,
                CHANGE COLUMN tag_description tag_description TEXT         NULL DEFAULT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER tag_name;
        ');

        $conn->execute('
            ALTER TABLE msz_comments_categories
                CHANGE COLUMN category_name category_name VARCHAR(255) NOT NULL COLLATE "ascii_bin" AFTER category_id;
        ');

        $conn->execute('
            ALTER TABLE msz_comments_posts
                CHANGE COLUMN comment_text comment_text TEXT NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER comment_reply_to;
        ');

        $conn->execute('
            ALTER TABLE msz_config
                CHANGE COLUMN config_name config_name VARCHAR(100) NOT NULL COLLATE "ascii_general_ci" FIRST;
        ');

        $conn->execute('
            ALTER TABLE msz_emoticons
                CHANGE COLUMN emote_url emote_url VARCHAR(255) NOT NULL COLLATE "ascii_bin" AFTER emote_hierarchy;
        ');

        $conn->execute('
            ALTER TABLE msz_emoticons_strings
                CHANGE COLUMN emote_string emote_string VARCHAR(50) NOT NULL COLLATE "ascii_general_ci" AFTER emote_string_order;
        ');

        $conn->execute('
            ALTER TABLE msz_forum_categories
                CHANGE COLUMN forum_name        forum_name        VARCHAR(255) NOT NULL          COLLATE "utf8mb4_unicode_520_ci" AFTER forum_parent,
                CHANGE COLUMN forum_description forum_description TEXT         NULL DEFAULT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER forum_type,
                CHANGE COLUMN forum_icon        forum_icon        VARCHAR(50)  NULL DEFAULT NULL COLLATE "ascii_bin"              AFTER forum_description,
                CHANGE COLUMN forum_link        forum_link        VARCHAR(255) NULL DEFAULT NULL COLLATE "ascii_bin"              AFTER forum_colour;
        ');

        $conn->execute('
            ALTER TABLE msz_forum_posts
                CHANGE COLUMN post_text post_text MEDIUMTEXT NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER post_ip;
        ');

        $conn->execute('
            ALTER TABLE msz_forum_topics
                CHANGE COLUMN topic_title topic_title VARCHAR(255) NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER topic_type;
        ');

        $conn->execute('
            ALTER TABLE msz_forum_topics_redirects
                CHANGE COLUMN topic_redir_url topic_redir_url VARCHAR(255) NOT NULL COLLATE "ascii_bin" AFTER user_id;
        ');

        $conn->execute('
            ALTER TABLE msz_login_attempts
                CHANGE COLUMN attempt_country    attempt_country    CHAR(2) NOT NULL DEFAULT "XX" COLLATE "ascii_general_ci"       AFTER attempt_ip,
                CHANGE COLUMN attempt_user_agent attempt_user_agent TEXT    NOT NULL              COLLATE "utf8mb4_unicode_520_ci" AFTER attempt_created;
        ');

        $conn->execute('
            ALTER TABLE msz_news_categories
                CHANGE COLUMN category_name        category_name        VARCHAR(255) NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER category_id,
                CHANGE COLUMN category_description category_description TEXT         NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER category_name;
        ');

        $conn->execute('
            ALTER TABLE msz_news_posts
                CHANGE COLUMN post_title post_title VARCHAR(255) NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER post_is_featured,
                CHANGE COLUMN post_text  post_text  TEXT         NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER post_title;
        ');

        $conn->execute('
            ALTER TABLE msz_profile_fields
                CHANGE COLUMN field_key   field_key   VARCHAR(50)  NOT NULL COLLATE "ascii_general_ci"       AFTER field_order,
                CHANGE COLUMN field_title field_title VARCHAR(50)  NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER field_key,
                CHANGE COLUMN field_regex field_regex VARCHAR(255) NOT NULL COLLATE "ascii_bin"              AFTER field_title;
        ');

        $conn->execute('
            ALTER TABLE msz_profile_fields_formats
                CHANGE COLUMN format_regex   format_regex   VARCHAR(255) NULL     DEFAULT NULL COLLATE "ascii_bin"              AFTER field_id,
                CHANGE COLUMN format_link    format_link    VARCHAR(255) NULL     DEFAULT NULL COLLATE "ascii_bin"              AFTER format_regex,
                CHANGE COLUMN format_display format_display VARCHAR(255) NOT NULL DEFAULT "%s" COLLATE "utf8mb4_unicode_520_ci" AFTER format_link;
        ');

        $conn->execute('
            ALTER TABLE msz_profile_fields_values
                CHANGE COLUMN field_value field_value VARCHAR(255) NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER format_id;
        ');

        $conn->execute('
            ALTER TABLE msz_roles
                CHANGE COLUMN role_name        role_name        VARCHAR(255) NOT NULL              COLLATE "utf8mb4_unicode_520_ci" AFTER role_hierarchy,
                CHANGE COLUMN role_title       role_title       VARCHAR(64)  NULL     DEFAULT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER role_name,
                CHANGE COLUMN role_description role_description TEXT         NULL     DEFAULT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER role_title;
        ');

        $conn->execute('
            ALTER TABLE msz_sessions
                CHANGE COLUMN session_user_agent session_user_agent TEXT    NOT NULL              COLLATE "utf8mb4_unicode_520_ci" AFTER session_ip_last,
                CHANGE COLUMN session_country    session_country    CHAR(2) NOT NULL DEFAULT "XX" COLLATE "ascii_general_ci"       AFTER session_client_info;
        ');

        $conn->execute('
            ALTER TABLE msz_users
                CHANGE COLUMN username               username               VARCHAR(255) NOT NULL              COLLATE "utf8mb4_unicode_520_ci" AFTER user_id,
                CHANGE COLUMN password               password               VARCHAR(255) NULL     DEFAULT NULL COLLATE "ascii_bin"              AFTER username,
                CHANGE COLUMN email                  email                  VARCHAR(255) NOT NULL              COLLATE "utf8mb4_unicode_520_ci" AFTER password,
                CHANGE COLUMN user_country           user_country           CHAR(2)      NOT NULL DEFAULT "XX" COLLATE "ascii_general_ci"       AFTER user_super,
                CHANGE COLUMN user_totp_key          user_totp_key          CHAR(26)     NULL     DEFAULT NULL COLLATE "ascii_bin"              AFTER display_role,
                CHANGE COLUMN user_about_content     user_about_content     TEXT         NULL     DEFAULT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER user_totp_key,
                CHANGE COLUMN user_signature_content user_signature_content TEXT         NULL     DEFAULT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER user_about_parser,
                CHANGE COLUMN user_title             user_title             VARCHAR(64)  NULL     DEFAULT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER user_background_settings;
        ');

        $conn->execute('
            ALTER TABLE msz_users_bans
                CHANGE COLUMN ban_reason_public  ban_reason_public  TEXT NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER ban_severity,
                CHANGE COLUMN ban_reason_private ban_reason_private TEXT NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER ban_reason_public;
        ');

        $conn->execute('
            ALTER TABLE msz_users_modnotes
                CHANGE COLUMN note_title note_title VARCHAR(255) NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER note_created,
                CHANGE COLUMN note_body  note_body  TEXT         NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER note_title;
        ');

        $conn->execute('
            ALTER TABLE msz_users_password_resets
                CHANGE COLUMN verification_code verification_code CHAR(12) NULL DEFAULT NULL COLLATE "ascii_general_ci" AFTER reset_requested;
        ');

        $conn->execute('
            ALTER TABLE msz_users_warnings
                CHANGE COLUMN warn_body warn_body TEXT NOT NULL COLLATE "utf8mb4_unicode_520_ci" AFTER mod_id;
        ');
    }
}
