<?php

use Licenzo\Framework\Database\Migration\Migration;

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

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

    public function up()
    {
        return $this->create($this->table, [
            'id'             => 'BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY',
            'invoice_id'     => 'BIGINT UNSIGNED NOT NULL',
            'line_type'      => 'VARCHAR(50) NOT NULL',
            'reference_type' => 'VARCHAR(100) NOT NULL',
            'reference_id'   => 'BIGINT UNSIGNED NULL',
            'description'    => 'TEXT NULL',
            'quantity'       => 'DECIMAL(12,4) NOT NULL DEFAULT 1.0000',
            'unit_amount'    => 'BIGINT NOT NULL DEFAULT 0',
            'line_total'     => 'BIGINT NOT NULL DEFAULT 0',
            'currency'       => 'VARCHAR(10) NOT NULL DEFAULT "USD"',
            'meta'           => 'LONGTEXT NULL',
            'created_at'     => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP',
            'updated_at'     => 'TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
        ], [
            ['type' => 'KEY', 'name' => 'idx_invoice_id', 'columns' => ['invoice_id']],
        ]);
    }

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