<?php

if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * Migration version 1
 *
 * @param string $collate
 *
 * @return array CREATE TABLE SQL statements
 */
return function (string $collate) {
    global $wpdb;

    return [
        "CREATE TABLE {$wpdb->prefix}linksy_links (
            id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
            post_id INT(20) NOT NULL,
            post_type text,
            post_title text,
            clean_url text,
            raw_url text,
            host text,
            anchor text,
            score DECIMAL(10,2) NULL DEFAULT NULL,
            to_post_id INT(20) NULL DEFAULT NULL,
            is_internal tinyint(1) DEFAULT '0',
            is_broken tinyint(1) DEFAULT '0',
            aria_label VARCHAR(255) DEFAULT NULL,
            target_attribute VARCHAR(255) DEFAULT NULL,
            rel VARCHAR(255) DEFAULT NULL,
            meta text,
            date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            PRIMARY KEY (id),
            KEY post_id (post_id),
            KEY clean_url (clean_url(500))
        ) $collate;",
        "CREATE TABLE {$wpdb->prefix}linksy_broken_links (
            id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
            post_id int(20) NOT NULL,
            anchor text,
            parser_type text,
            url text,
            last_checked datetime NOT NULL,
            check_count int(11) DEFAULT 0,
            final_url text,
            log text,
            http_code smallint(6),
            status_code varchar(10),
            status_text varchar(255),
            response_time float DEFAULT 0,
            result_hash text,
            may_recheck tinyint(1) DEFAULT 0,
            is_timeout tinyint(1) DEFAULT 0,
            is_broken tinyint(1) DEFAULT 0,
            is_warning tinyint(1) DEFAULT 0,
            is_dismissed tinyint(1) DEFAULT 0,
            date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
            PRIMARY KEY (id)
        ) $collate;",
    ];
};
