<?php
namespace GemBoards\Database;

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

use GemBoards\Utils\Helper;

class CreateCardsTable {

	public static function up( $prefix, $charset_collate ) {
		$table_name = $prefix . Helper::BOARD_CARD_TABLE_NAME;
		$sql        = "CREATE TABLE $table_name (
            id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
            task_id BIGINT(20) UNSIGNED NOT NULL,
            board_id BIGINT(20) UNSIGNED NOT NULL,
            column_id BIGINT(20) UNSIGNED NOT NULL,
            sprint_id BIGINT(20) UNSIGNED,
            sort_order INT,
            is_completed TINYINT(1) DEFAULT 0,
            archived TINYINT(1) DEFAULT 0,
            due_date DATE NULL DEFAULT NULL,
            story_point SMALLINT UNSIGNED NOT NULL DEFAULT 0,
            updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
            completed_at DATETIME DEFAULT NULL,
            PRIMARY KEY  (id),
		    KEY `idx_cards_board_archived_sort` (`board_id`, `archived`, `sort_order`),
		    KEY `idx_card_sprint_id` (`sprint_id`)
        ) $charset_collate;";
		dbDelta( $sql );
	}

}
