<?php
/******************************************************************************
 *   ______                                                                   *
 *  /       \                                                                 *
 * /$$$$$$  | ________  __    __   ______    ______                           *
 * $$ |__$$ |/        |/  |  /  | /      \  /      \                          *
 * $$    $$ |$$$$$$$$/ $$ |  $$ |/$$$$$$  |/$$$$$$  |                         *
 * $$$$$$$$ |  /  $$/  $$ |  $$ |$$ |  $$/ $$    $$ |                         *
 * $$ |  $$ | /$$$$/__ $$ \__$$ |$$ |      $$$$$$$$/                          *
 * $$ |  $$ |/$$      |$$    $$/ $$ |      $$       |                         *
 * $$/   $$/ $$$$$$$$/  $$$$$$/  $$/        $$$$$$$/                          *
 *                                                                            *
 * @PROJECT    : 3D Preview Extension [Magetop.com]                           *
 * @AUTHOR     : Azure - Developer                                            *
 * @COPYRIGHT  : © 2019  Magetop.com                                          *
 * @LINK       : https://Magetop.com                                          *
 * @CREATED    :  10/01/2022                                                  *
 ******************************************************************************/

namespace Magetop\Advancepreview\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
class UpgradeSchema implements UpgradeSchemaInterface
{
    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $setup->startSetup();
        if (version_compare($context->getVersion(), '2.5.3') < 0) {
            $magetopPreviewProductHistory = $installer->getTable('magetop_preview_product_history');
            if ($setup->getConnection()->isTableExists($magetopPreviewProductHistory) != true) {
                $tableMagetopPreviewProductHistory = $setup->getConnection()
                    ->newTable($magetopPreviewProductHistory)
                    ->addColumn(
                        'history_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                        'Id'
                    )
                    ->addColumn(
                        'product_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false],
                        'Quote Item id'
                    )->addColumn(
                        'customer_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false],
                        'Customer Id'
                    )
                    ->addColumn(
                        'last_access',
                        \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        null,
                        ['nullable' => true],
                        'Time Access'
                    )
                    ->setComment('Magetop Product History')
                    ->setOption('type', 'InnoDB')
                    ->setOption('charset', 'utf8');
                $setup->getConnection()->createTable($tableMagetopPreviewProductHistory);
            }
        }
        if (version_compare($context->getVersion(), '2.5.4') < 0) {
            $model3D = $installer->getTable('magetop_3d_lists');
            if ($setup->getConnection()->isTableExists($model3D) != true) {
                $tableModel3D  = $setup->getConnection()
                    ->newTable($model3D)
                    ->addColumn(
                        'threed_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                        'Id'
                    )
                    ->addColumn(
                        'product_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Quote Item id'
                    )
                    ->addColumn(
                        'type',
                        \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'TYpe id'
                    )
                    ->addColumn(
                        'created_at',
                        \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        null,
                        ['nullable' => true],
                        'Create At'
                    )
                    ->setComment('3D model')
                    ->setOption('type', 'InnoDB')
                    ->setOption('charset', 'utf8');
                $setup->getConnection()->createTable($tableModel3D);
            }
        }
        if (version_compare($context->getVersion(), '2.5.5') < 0) {
            $preview3dTable = $installer->getTable('magetop_3d_lists');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($preview3dTable) == true) {
                // Declare data
                $columns = [
                    'title' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'title',

                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($preview3dTable, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.5.6') < 0) {
            $preview3dTable = $installer->getTable('magetop_3d_lists');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($preview3dTable) == true) {
                // Declare data
                $columns = [
                    'filename' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'filename',

                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($preview3dTable, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.5.7') < 0) {
            $previewCustomDiscount = $installer->getTable('magetop_preview_custom_discount');
            if ($setup->getConnection()->isTableExists($previewCustomDiscount) != true) {
                $tablePreviewCustomDiscount  = $setup->getConnection()
                    ->newTable($previewCustomDiscount)
                    ->addColumn(
                        'discount_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                        'Id'
                    )
                    ->addColumn(
                        'product_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Product Id'
                    )
                    ->addColumn(
                        'discount_title',
                        \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        500,
                        ['nullable' => false, 'default' => ''],
                        'Discount Title'
                    )
                    ->addColumn(
                        'discount_price',
                        \Magento\Framework\DB\Ddl\Table::TYPE_FLOAT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Discount Price'
                    )
                    ->addColumn(
                        'discount_amount',
                        \Magento\Framework\DB\Ddl\Table::TYPE_FLOAT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Discount amount'
                    )
                    ->addColumn(
                        'created_at',
                        \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                        null,
                        ['nullable' => false,
                         'default'  => CURRENT_TIMESTAMP  
                        ],
                        'Create At'
                    )
                    ->setComment('Magetop Preview Discount Table')
                    ->setOption('type', 'InnoDB')
                    ->setOption('charset', 'utf8');
                $setup->getConnection()->createTable($tablePreviewCustomDiscount);
            }
        }
        if (version_compare($context->getVersion(), '2.5.8') < 0) {
            $previewAdditionalOptions = $installer->getTable('magetop_preview_additional_option');
            if ($setup->getConnection()->isTableExists($previewAdditionalOptions) != true) {
                $tablePreviewAdditionalOptions  = $setup->getConnection()
                    ->newTable($previewAdditionalOptions)
                    ->addColumn(
                        'addition_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                        'Id'
                    )
                    ->addColumn(
                        'product_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Product Id'
                    )
                    ->addColumn(
                        'status',
                        \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        null,
                        ['nullable' => false, 'default' => 1],
                        'Status Id'
                    )
                    ->addColumn(
                        'title',
                        \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        500,
                        ['nullable' => false, 'default' => ''],
                        'Title'
                    )
                    ->addColumn(
                        'description',
                        \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        500,
                        ['nullable' => false, 'default' => ''],
                        'description'
                    )
                    ->addColumn(
                        'price',
                        \Magento\Framework\DB\Ddl\Table::TYPE_FLOAT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Price'
                    )
                    ->addColumn(
                        'created_at',
                        \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        null,
                        ['nullable' => true],
                        'Create At'
                    )
                    ->setComment('Magetop Preview Discount Table')
                    ->setOption('type', 'InnoDB')
                    ->setOption('charset', 'utf8');
                $setup->getConnection()->createTable($tablePreviewAdditionalOptions);
            }
        }
        if (version_compare($context->getVersion(), '2.5.9') < 0) {
            $preview3dTable = $installer->getTable('magetop_3d_lists');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($preview3dTable) == true) {
                // Declare data
                $columns = [
                    'file_preview' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'file preview',

                    ],
                    'position' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        ['nullable' => true, 'default' => 0],
                        'comment' => 'file preview',

                    ],
                    'preview_light' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        ['nullable' => true, 'default' => 0],
                        'comment' => 'file light',

                    ],
                    'preview_zoom' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        ['nullable' => true, 'default' => 0],
                        'comment' => 'file light',

                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($preview3dTable, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.6.0') < 0) {
            $preview3dTable = $installer->getTable('magetop_3d_lists');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($preview3dTable) == true) {
                // Declare data
                $columns = [
                    'thumbnail' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'thumbnail',

                    ],
                    'texture' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'texture',

                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($preview3dTable, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.6.1') < 0) {
            $preview3dTable = $installer->getTable('magetop_3d_lists');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($preview3dTable) == true) {
                // Declare data
                $columns = [
                    'texture_width' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        ['nullable' => true, 'default' => 0],
                        'comment' => 'texture_width',

                    ],
                    'texture_height' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => 0],
                        'comment' => 'texture_height',

                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($preview3dTable, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.6.1') < 0) {
            $preview3dTable = $installer->getTable('magetop_3d_lists');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($preview3dTable) == true) {
                // Declare data
                $columns = [
                    'texture_width' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        ['nullable' => true, 'default' => 0],
                        'comment' => 'texture_width',

                    ],
                    'texture_height' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => 0],
                        'comment' => 'texture_height',

                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($preview3dTable, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.6.2') < 0) {
            $preview3dTable = $installer->getTable('magetop_3d_lists');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($preview3dTable) == true) {
                // Declare data
                $columns = [
                    'is_default' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        ['nullable' => true, 'default' => 2],
                        'comment' => 'is_default',

                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($preview3dTable, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.6.3') < 0) {
            $preview3dTable = $installer->getTable('magetop_3d_lists');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($preview3dTable) == true) {
                // Declare data
                $columns = [
                    'folder_preview' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'is_default',

                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($preview3dTable, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.6.8') < 0) {
            $magetopCartProjectItems = $installer->getTable('magetop_cart_project_items');
            if ($setup->getConnection()->isTableExists($magetopCartProjectItems) != true) {
                $tablePagetopCartProjectItems  = $setup->getConnection()
                    ->newTable($magetopCartProjectItems)
                    ->addColumn(
                        'cart_project_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                        'Id'
                    )
                    ->addColumn(
                        'project_item_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Product Id'
                    )
                    ->addColumn(
                        'customer_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        255,
                        ['nullable' => false, 'default' => 0],
                        'Customer ID Id'
                    )
                    ->addColumn(
                        'created_at',
                        \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        null,
                        ['nullable' => true],
                        'Create At'
                    )
                    ->setComment('magetop_cart_project_items')
                    ->setOption('type', 'InnoDB')
                    ->setOption('charset', 'utf8');
                $setup->getConnection()->createTable($tablePagetopCartProjectItems);
            }
        }
        if (version_compare($context->getVersion(), '2.6.9') < 0) {
            $magetopDailyShipping = $installer->getTable('magetop_preview_daily_shipping');
            if ($setup->getConnection()->isTableExists($magetopDailyShipping) != true) {
                $tableMagetopDailyShipping = $setup->getConnection()
                    ->newTable($magetopDailyShipping)
                    ->addColumn(
                        'daily_shipping_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                        'Id'
                    )
                    ->addColumn(
                        'status',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Product Id'
                    )
                    ->addColumn(
                        'amount',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        255,
                        ['nullable' => false, 'default' => 0],
                        'Customer ID Id'
                    )
                    ->addColumn(
                        'created_at',
                        \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        null,
                        ['nullable' => true],
                        'Create At'
                    )
                    ->setComment('magetop_preview_daily_shipping')
                    ->setOption('type', 'InnoDB')
                    ->setOption('charset', 'utf8');
                $setup->getConnection()->createTable($tableMagetopDailyShipping);
            }
        }
        if (version_compare($context->getVersion(), '2.7.0') < 0) {
            $magetopDailyShippingTable = $installer->getTable('magetop_preview_daily_shipping');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($magetopDailyShippingTable) == true) {
                // Declare data
                $columns = [
                    'product_id' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        ['nullable' => true, 'default' => 0],
                        'comment' => 'product_id',

                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($magetopDailyShippingTable, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.7.1') < 0) {
            $magetopDailyShippingTable = $installer->getTable('magetop_preview_daily_shipping');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($magetopDailyShippingTable) == true) {
                // Declare data
                $columns = [
                    'delivery_type' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'Delivery Type',

                    ],
                    'delivery_days' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        ['nullable' => true, 'default' => 0],
                        'comment' => 'Delivery days',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($magetopDailyShippingTable, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.7.2') < 0) {
            $magetopPreviewOffer = $installer->getTable('magetop_preview_offer');
            if ($setup->getConnection()->isTableExists($magetopPreviewOffer) != true) {
                $tableMagetopPreviewOffer = $setup->getConnection()
                    ->newTable($magetopPreviewOffer)
                    ->addColumn(
                        'offer_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                        'Id'
                    )
                    ->addColumn(
                        'info_request',
                        \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        null,
                        ['nullable' => false, 'default' => ''],
                        'info_request'
                    )
                    ->setComment('magetop_preview_offer')
                    ->setOption('type', 'InnoDB')
                    ->setOption('charset', 'utf8');
                $setup->getConnection()->createTable($tableMagetopPreviewOffer);
            }
        }
        if (version_compare($context->getVersion(), '2.7.3') < 0) {
            $magetopCustomOrderItems = $installer->getTable('magetop_preview_order_items');
            if ($setup->getConnection()->isTableExists($magetopCustomOrderItems) != true) {
                $tableMagetopCustomOrderItems  = $setup->getConnection()
                    ->newTable($magetopCustomOrderItems)
                    ->addColumn(
                        'custom_item_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                        'Id'
                    )
                    ->addColumn(
                        'order_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Order Id'
                    )
                    ->addColumn(
                        'product_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'product id'
                    )
                    ->addColumn(
                        'item_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Item id'
                    )
                    ->addColumn(
                        'status',
                        \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        255,
                        ['nullable' => false, 'default' => ''],
                        'Status'
                    )   ->addColumn(
                        'info_request',
                        \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        null,
                        ['nullable' => false, 'default' => ''],
                        'Info Request'
                    )
                    ->addColumn(
                        'created_at',
                        \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        null,
                        ['nullable' => true],
                        'Create At'
                    )  ->addColumn(
                        'updated_at',
                        \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        null,
                        ['nullable' => true],
                        'Create At'
                    )
                    ->setComment('magetop_preview_order_items')
                    ->setOption('type', 'InnoDB')
                    ->setOption('charset', 'utf8');
                $setup->getConnection()->createTable($tableMagetopCustomOrderItems);
            }
        }
        if (version_compare($context->getVersion(), '2.7.4') < 0) {
            $previewAdditionalOptions = $installer->getTable('magetop_preview_additional_option');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($previewAdditionalOptions) == true) {
                // Declare data
                $columns = [
                    'updated_at' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        ['nullable' => true],
                        'comment' => 'Update at',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($previewAdditionalOptions, $name, $definition);
                }
            }
            $magetopDailyShippingTable = $installer->getTable('magetop_preview_daily_shipping');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($magetopDailyShippingTable) == true) {
                // Declare data
                $columns = [
                    'updated_at' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        ['nullable' => true],
                        'comment' => 'Update at',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($magetopDailyShippingTable, $name, $definition);
                }
            }
            $previewCustomDiscount = $installer->getTable('magetop_preview_custom_discount');
            // Check if the table already exists
            if ($setup->getConnection()->isTableExists($previewCustomDiscount) == true) {
                // Declare data
                $columns = [
                    'updated_at' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        ['nullable' => true],
                        'comment' => 'Update at',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($previewCustomDiscount, $name, $definition);
                }
            }

        }
        if (version_compare($context->getVersion(), '2.7.5') < 0) {
            $magetopOrderTracking = $installer->getTable('magetop_preview_order_tracking');
            if ($setup->getConnection()->isTableExists($magetopOrderTracking) != true) {
                $tableMagetopOrderTracking  = $setup->getConnection()
                    ->newTable($magetopOrderTracking)
                    ->addColumn(
                        'preview_tracking_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                        'Id'
                    )
                    ->addColumn(
                        'order_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Order Id'
                    )
                    ->addColumn(
                        'product_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'product id'
                    )
                    ->addColumn(
                        'item_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Item id'
                    )
                    ->addColumn(
                        'status',
                        \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        255,
                        ['nullable' => false, 'default' => ''],
                        'Status'
                    )
                    ->addColumn(
                        'tracking_number',
                        \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        500,
                        ['nullable' => true, 'default' => ''],
                        'tracking number'
                    )
                    ->addColumn(
                        'tracking_link',
                        \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        500,
                        ['nullable' => true, 'default' => ''],
                        'tracking number'
                    )
                    ->addColumn(
                        'courier_company',
                        \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        500,
                        ['nullable' => true, 'default' => ''],
                        'courier company'
                    )
                    ->addColumn(
                        'created_at',
                        \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        null,
                        ['nullable' => true],
                        'Create At'
                    )  ->addColumn(
                        'updated_at',
                        \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        null,
                        ['nullable' => true],
                        'Create At'
                    )
                    ->setComment('Magetop Order Tracking item')
                    ->setOption('type', 'InnoDB')
                    ->setOption('charset', 'utf8');
                $setup->getConnection()->createTable($tableMagetopOrderTracking);
            }
        }
        if (version_compare($context->getVersion(), '2.7.6') < 0) {
            $magetopCustomOrderItems = $installer->getTable('magetop_preview_order_items');
            if ($setup->getConnection()->isTableExists($magetopCustomOrderItems) == true) {
                // Declare data
                $columns = [
                    'custom_design' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true],
                        'comment' => 'custom_design',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($magetopCustomOrderItems, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.7.7') < 0) {
            $magetopCustomOrderItems = $installer->getTable('magetop_preview_order_items');
            if ($setup->getConnection()->isTableExists($magetopCustomOrderItems) == true) {
                // Declare data
                $columns = [
                    'admin_upload_design' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'custom_design',
                    ],
                    'admin_upload_status' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        ['nullable' => true,'default' => 0],
                        'comment' => 'custom_design',
                    ],
                    'is_admin_create' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        ['nullable' => true,'default' => 0],
                        'comment' => 'custom_design',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($magetopCustomOrderItems, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.7.8') < 0) {
            $magetopCustomOrderItems = $installer->getTable('magetop_preview_order_items');
            if ($setup->getConnection()->isTableExists($magetopCustomOrderItems) == true) {
                // Declare data
                $columns = [
                    'tracking_info' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'tracking_info',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($magetopCustomOrderItems, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.7.9') < 0) {
            $magetopCustomerEmailSetting = $installer->getTable('magetop_customer_email_setting');
            if ($setup->getConnection()->isTableExists($magetopCustomerEmailSetting) != true) {
                $tableMagetopCustomerEmailSetting  = $setup->getConnection()
                    ->newTable($magetopCustomerEmailSetting)
                    ->addColumn(
                        'configure_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                        'Id'
                    )
                    ->addColumn(
                        'customer_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'Customer Id'
                    )
                    ->addColumn(
                        'request_offer',
                        \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'request_offer'
                    )
                    ->addColumn(
                        'status_in_progress',
                        \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'status_in_progress'
                    )
                    ->addColumn(
                        'status_checking_myfit',
                        \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'status_in_progress'
                    )
                    ->addColumn(
                        'status_design_approved',
                        \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'status_in_progress'
                    )
                    ->addColumn(
                        'status_design_failed',
                        \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'status_design_failed'
                    )
                    ->addColumn(
                        'status_design_fully_approved',
                        \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'status_design_fully_approved'
                    )
                    ->addColumn(
                        'status_shipping',
                        \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'status_design_fully_approved'
                    )
                    ->addColumn(
                        'status_shipped',
                        \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'status_shipped'
                    )
                    ->addColumn(
                        'status_delivered',
                        \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'status_delivered'
                    )
                    ->addColumn(
                        'created_at',
                        \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        null,
                        ['nullable' => true],
                        'Create At'
                    )  ->addColumn(
                        'updated_at',
                        \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
                        null,
                        ['nullable' => true],
                        'Create At'
                    )
                    ->setComment('magetopCustomerEmailSetting')
                    ->setOption('type', 'InnoDB')
                    ->setOption('charset', 'utf8');
                $setup->getConnection()->createTable($tableMagetopCustomerEmailSetting);
            }
        }
        if (version_compare($context->getVersion(), '2.8.0') < 0) {
            $magetopCustomOrderItems = $installer->getTable('magetop_preview_order_items');
            if ($setup->getConnection()->isTableExists($magetopCustomOrderItems) == true) {
                // Declare data
                $columns = [
                    'project_name' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'project name',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($magetopCustomOrderItems, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.8.1') < 0) {
            $magetopCustomOrderItems = $installer->getTable('magetop_preview_order_items');
            if ($setup->getConnection()->isTableExists($magetopCustomOrderItems) == true) {
                // Declare data
                $columns = [
                    'invoice_id' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        ['nullable' => true, 'default' => 0],
                        'comment' => 'invoice_id',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($magetopCustomOrderItems, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.8.2') < 0) {
            $magetopCustomOrderItems = $installer->getTable('magetop_preview_order_items');
            if ($setup->getConnection()->isTableExists($magetopCustomOrderItems) == true) {
                // Declare data
                $columns = [
                    'is_new_proof' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        ['nullable' => true, 'default' => 0],
                        'comment' => 'is_new_proof',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($magetopCustomOrderItems, $name, $definition);
                }
            }
        }
        if (version_compare($context->getVersion(), '2.8.3') < 0) {
            $magetopCustomOrderItems = $installer->getTable('magetop_preview_order_items');
            if ($setup->getConnection()->isTableExists($magetopCustomOrderItems) == true) {
                // Declare data
                $columns = [
                    'preview_model' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'preview_model',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($magetopCustomOrderItems, $name, $definition);
                }
            }
        }
        //table magetop_preview_orders
        if (version_compare($context->getVersion(), '2.8.4') < 0) {
            $magetopPreviewCustomerOrders = $installer->getTable('magetop_preview_orders');
            if ($setup->getConnection()->isTableExists($magetopPreviewCustomerOrders) != true) {
                $magetopPreviewCustomerOrdersTable  = $setup->getConnection()
                    ->newTable($magetopPreviewCustomerOrders)
                    ->addColumn(
                        'magetop_order_preview_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true],
                        'Id'
                    )
                    ->addColumn(
                        'order_id',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => false, 'default' => 0],
                        'order_id Id'
                    )
                    ->addColumn(
                        'order_status',
                        \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                        null,
                        ['nullable' => true, 'default' => 0],
                        'request_offer'
                    )
                    ->addColumn(
                        'order_total',
                        \Magento\Framework\DB\Ddl\Table::TYPE_FLOAT,
                        null,
                        ['nullable' => true, 'default' => 0],
                        'order_total'
                    )
                    ->setComment('magetop_preview_orders')
                    ->setOption('type', 'InnoDB')
                    ->setOption('charset', 'utf8');
                $setup->getConnection()->createTable($magetopPreviewCustomerOrdersTable);
            }
        }
        // update table  magetop_preview_order_items
        if (version_compare($context->getVersion(), '2.8.5') < 0) {
            $magetopCustomOrderItems = $installer->getTable('magetop_preview_order_items');
            if ($setup->getConnection()->isTableExists($magetopCustomOrderItems) == true) {
                // Declare data
                $columns = [
                    'paid_status' => [
                        'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                        ['nullable' => true, 'default' => ''],
                        'comment' => 'paid_status',
                    ],
                ];
                $connection = $setup->getConnection();
                foreach ($columns as $name => $definition) {
                    $connection->addColumn($magetopCustomOrderItems, $name, $definition);
                }
            }
        }
        $setup->endSetup();
    }
}
