<?php

use Licenzo\Framework\Database\Migration\Migration;

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

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

    public function up()
    {
        return $this->create($this->table, [
            'id'               => 'BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY',
            'uuid'             => 'CHAR(36) NOT NULL UNIQUE',
            'license_key'      => 'VARCHAR(191) NOT NULL UNIQUE',
            'customer_id'      => 'BIGINT UNSIGNED NOT NULL',
            'subscription_id'  => 'BIGINT UNSIGNED NULL COMMENT "Every license belongs to a subscription"',
            'status'           => 'VARCHAR(50) NULL DEFAULT "active"',
            'activation_count' => 'INT UNSIGNED DEFAULT 0',
            'activation_limit' => 'INT UNSIGNED DEFAULT 0',
            'expire_date'      => 'DATE NULL',
            'support_till'     => 'DATE NULL',
            'activated_at'     => 'TIMESTAMP NOT NULL',
            'config'           => 'LONGTEXT NULL',
            'created_at'       => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP',
            'updated_at'       => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
        ], [
            ['type' => 'KEY', 'name' => 'idx_customer_id', 'columns' => ['customer_id']],
        ]);
    }

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