<?php
declare(strict_types=1);

namespace EHxMe\Database\Migrations;

use EHxMe\Database\DBMigrator;

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

class Payment
{
    /**
     * Migrate the table.
     *
     * @return bool
     */
    public static function migrate($force = false): bool
    {
        global $wpdb;

        $charsetCollate = $wpdb->get_charset_collate();

        $table_name = $wpdb->prefix . 'ehxme_payments';

        $sql = "CREATE TABLE $table_name (
            `id` INT(11) NOT NULL AUTO_INCREMENT,
            `user_id` BIGINT UNSIGNED NOT NULL,
            `amount` DECIMAL(8,2) NOT NULL,
            `charge` DECIMAL(8,2) DEFAULT 0,
            `method` VARCHAR(30) DEFAULT NULL,
            `status` ENUM('pending','success','cancel') DEFAULT 'pending',
            `additional_data` JSON DEFAULT NULL,
            `created_at` TIMESTAMP NULL DEFAULT NULL,
            `updated_at` TIMESTAMP NULL DEFAULT NULL,
            PRIMARY KEY (`id`)
        ) $charsetCollate;";

        return DBMigrator::runSQL($sql, $force ? $table_name : null);
    }
}