<?php

use Licenzo\Framework\Database\Migration\Migration;

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

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

    public function up()
    {
        return $this->create($this->table, [
            'id'               => 'BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY',
            'uuid'             => 'VARCHAR(191) NOT NULL UNIQUE',
            'product_id'       => 'BIGINT UNSIGNED NOT NULL',
            'provider_id'      => 'VARCHAR(255) DEFAULT NULL', // canonical provider variation/price reference
            'name'             => 'VARCHAR(255) NOT NULL',
            'billing_cycle'    => 'ENUM("onetime","monthly","yearly","weekly","lifetime") DEFAULT "monthly"',
            'currency'         => 'VARCHAR(10) NOT NULL DEFAULT "USD"',
            'regular_price'    => 'BIGINT NOT NULL DEFAULT 0',
            'sale_price'       => 'BIGINT DEFAULT NULL',
            'max_activations'  => 'INT UNSIGNED DEFAULT 1',
            'trial_days'       => 'INT UNSIGNED DEFAULT 0',
            'support_for_unit' => 'ENUM("day","month","year") DEFAULT "day"',
            'support_for'      => 'INT DEFAULT NULL',
            'created_at'       => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP',
            'updated_at'       => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
        ], [
            ['type' => 'KEY', 'name' => 'idx_product_id', 'columns' => ['product_id']],
        ]);
    }

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