<?php

use Licenzo\Framework\Database\Migration\Migration;

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

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

    public function up()
    {
        return $this->create($this->table, [
            'id'               => 'BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY',
            'license_id'       => 'BIGINT UNSIGNED NOT NULL',
            'product_id'       => 'BIGINT UNSIGNED NOT NULL',
            'variation_id'     => 'BIGINT UNSIGNED DEFAULT NULL',
            'product_name'      => 'VARCHAR(255) NOT NULL',
            'variation_name'    => 'VARCHAR(255) NULL',
            'started_at'       => 'DATE NOT NULL',
            'expire_date'      => 'DATE NULL DEFAULT NULL',
            'activation_count' => 'INT DEFAULT 0',
            'created_at'       => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP',
            'updated_at'       => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
        ], [
            ['type' => 'KEY', 'name' => 'idx_license_id', 'columns' => ['license_id']],
        ]);
    }

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