<?php

use Licenzo\Framework\Database\Migration\Migration;

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

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

    public function up()
    {
        return $this->create($this->table, [
            'id'                => 'BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY',

            // Provider details
            'provider'          => 'VARCHAR(50) NOT NULL', // stripe, paypal, woocommerce
            'event_type'        => 'VARCHAR(100) NOT NULL', // customer.subscription.created, charge.succeeded, etc.
            'event_id'          => 'VARCHAR(255) NULL', // Provider's event ID

            // Webhook data
            'payload'           => 'LONGTEXT NOT NULL', // Full webhook payload (JSON)
            'headers'           => 'LONGTEXT NULL', // Request headers (JSON)

            // Processing status
            'status'            => 'VARCHAR(50) NOT NULL DEFAULT "pending"', // pending, processed, failed
            'error_message'     => 'TEXT NULL',
            'retry_count'       => 'INT UNSIGNED DEFAULT 0',

            // Timestamps
            'processed_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);
    }
};

