<?php

declare(strict_types=1);

namespace CloudXM\NFe\Persistence\Migrations;

use CloudXM\SDK\Contracts\MigrationInterface;

class WidenInvoiceSeriesColumn009 implements MigrationInterface
{
    public function __construct(private string $table_prefix = 'cloudxm_nfe_') {}

    public function run(): bool
    {
        global $wpdb;
        $table = $wpdb->prefix . $this->table_prefix . 'emissions';
        $wpdb->query("ALTER TABLE {$table} MODIFY COLUMN invoice_series varchar(20) DEFAULT NULL");
        return true;
    }

    public function rollback(): bool
    {
        global $wpdb;
        $table = $wpdb->prefix . $this->table_prefix . 'emissions';
        $wpdb->query("ALTER TABLE {$table} MODIFY COLUMN invoice_series varchar(3) DEFAULT NULL");
        return true;
    }

    public function getDescription(): string
    {
        return 'Widen invoice_series from varchar(3) to varchar(20)';
    }

    public function getVersion(): string
    {
        return '2.5.0';
    }
}
