<?php

declare(strict_types=1);

namespace Gls\GlsPoland\PrestaShop\Installer\Migration;

use Doctrine\DBAL\Schema\Schema;

final class Version1_2_0 extends AbstractMigration
{
    private const CARRIER_TABLE = 'gls_poland_carrier';

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

    public function up(Schema $schema): void
    {
        $tableName = $this->prefixTableName(self::CARRIER_TABLE);

        if (!$schema->hasTable($tableName)) {
            return;
        }

        $this->addColumn($schema->getTable($tableName), 'parcelshop_type', 'string')
            ->setLength(16)
            ->setNotnull(false);
    }

    public function down(Schema $schema): void
    {
        $tableName = $this->prefixTableName(self::CARRIER_TABLE);

        if (!$schema->hasTable($tableName)) {
            return;
        }

        $table = $schema->getTable($tableName);
        if ($table->hasColumn('parcelshop_type')) {
            $table->dropColumn('parcelshop_type');
        }
    }
}
