<?php
namespace TbiBank\FusionPay\Setup\Patch\Schema;

use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\DB\Ddl\Table;

use TbiBank\FusionPay\Logger\FusionPayLogger;

/**
 * Class AddTbiStatusColumn
 * This class defines a schema patch to add a 'tbi_status' column to the 'sales_order' table.
 */
class AddTbiStatusColumn implements SchemaPatchInterface
{
    /**
     * @var ModuleDataSetupInterface
     */
    private $moduleDataSetup;

    protected $fusionPayLogger;

    /**
     * Constructor for the schema patch.
     *
     * @param ModuleDataSetupInterface $moduleDataSetup Setup module data setup interface.
     */
    public function __construct(ModuleDataSetupInterface $moduleDataSetup, FusionPayLogger $fusionPayLogger)
    {
        $this->moduleDataSetup = $moduleDataSetup;
        $this->fusionPayLogger = $fusionPayLogger;
    }

    /**
     * Returns the array of patches that this patch depends on.
     *
     * @return array An array of dependencies.
     */
    public static function getDependencies()
    {
        return [];
    }

    /**
     * Returns the array of aliases for this patch.
     *
     * @return array An array of aliases.
     */
    public function getAliases()
    {
        return [];
    }

    /**
     * Applies the schema patch to add 'tbi_status' column to the 'sales_order' table.
     */
    public function apply()
    {
        $this->moduleDataSetup->startSetup();

        $this->fusionPayLogger->info('Applying AddTbiStatusColumn schema patch.');

        // Add the 'tbi_status' column to the 'sales_order' table
        $this->moduleDataSetup->getConnection()->addColumn(
            $this->moduleDataSetup->getTable('sales_order'),
            'tbi_status',
            [
                'type'      =>  Table::TYPE_TEXT,       // Column type is TEXT
                'length'    =>  255,
                'nullable'  =>  false,                  // The column is not nullable
                'comment'   =>  'TBI Status',           // Comment for the column
                'default'   =>   __( "In Progress" )    // Default value for the column
            ]
        );

        $this->moduleDataSetup->endSetup();
    }

    
}

