<?php

use Licenzo\Framework\Database\Migration\Migration;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

return new class extends Migration {
    protected $table = 'licenzo_idempotency_keys';

    public function up()
    {
        return $this->create($this->table, [
            'id'               => 'BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY',
            'provider'         => 'VARCHAR(50) NOT NULL',
            'event_scope'      => 'VARCHAR(100) NOT NULL',
            'event_key'        => 'VARCHAR(255) NOT NULL',
            'key_hash'         => 'CHAR(64) NOT NULL',
            'subscription_id'  => 'BIGINT UNSIGNED NULL',
            'customer_id'      => 'BIGINT UNSIGNED NULL',
            'status'           => 'VARCHAR(50) NOT NULL DEFAULT "processing"',
            'payload_checksum' => 'CHAR(64) NULL',
            'processed_at'     => 'TIMESTAMP NULL',
            'expires_at'       => 'TIMESTAMP NULL',
            'created_at'       => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP',
            'updated_at'       => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
        ]);
    }

    public function down()
    {
        return $this->drop($this->table);
    }
};
