<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        App\Support\SqliteCompat::statement(<<<'SQL'
CREATE TABLE `paypal_payments` (
`id` int UNSIGNED NOT NULL,
  `webhook_id` varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `parent_school_id` varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `order_id` varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `transaction_id` varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `status` varchar(32) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `amount` decimal(10,2) DEFAULT NULL,
  `currency` varchar(10) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `paypal_fee` decimal(10,2) DEFAULT NULL,
  `net_amount` decimal(10,2) DEFAULT NULL,
  `payer_email` varchar(128) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `merchant_id` varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `event_type` varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `summary` text COLLATE utf8mb4_general_ci,
  `raw_payload` longtext COLLATE utf8mb4_general_ci,
  `synced` tinyint(1) NOT NULL DEFAULT '0',
  `sync_attempts` int NOT NULL DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `paypal_payments`
  ADD PRIMARY KEY (`id`);
SQL
        );

        App\Support\SqliteCompat::statement(<<<'SQL'
ALTER TABLE `paypal_payments`
  MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT;
SQL
        );

    }

    public function down(): void
    {
        Schema::dropIfExists('paypal_payments');
    }
};