<?php
/**
 * CoderkubeTeam
 * Copyright(C) 06/2020 CoderkubeTeam <support@coderkube.com>
 * @package Coderkube_Brand
 * @copyright Copyright(C) 06/2020 CoderkubeTeam (https://coderkube.com/)
 * @author CoderkubeTeam <support@coderkube.com>
 */

namespace Coderkube\Brand\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\DB\Ddl\Table;
  
class InstallSchema implements InstallSchemaInterface
{
    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        $installer->startSetup();
  
        //ck_brand table
          $tableName = $installer->getTable('ck_brand');
        if ($installer->getConnection()->isTableExists($tableName) != true) {
            $table = $installer->getConnection()
                ->newTable($tableName)
            ->addColumn(
                'brand_id',
                Table::TYPE_INTEGER,
                null,
                ['identity' => true, 'nullable' => false , 'primary' => true],
                'Brand ID'
            )->addColumn(
                'name',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false,'default' => ''],
                'Name'
            )
            ->addColumn(
                'url',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false, 'default'=>''],
                'URL'
            )->addColumn(
                'image',
                Table::TYPE_TEXT,
                255,
                ['nullable' => false],
                'Brand Image'
            )->addColumn(
                'description',
                Table::TYPE_TEXT,
                255,
                ['unsigned' => true, 'nullable' => false],
                'Brand Description'
            )->addColumn(
                'position',
                Table::TYPE_INTEGER,
                255,
                ['unsigned' => true, 'nullable' => false],
                'Brand Position'
            )
            ->addColumn(
                'status',
                Table::TYPE_TEXT,
                null,
                ['nullable' => false, 'default' => ''],
                'Status'
            )
            ->addColumn(
                'created_at',
                Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false , 'default' =>Table::TIMESTAMP_INIT],
                'Created At'
            )
            ->addColumn(
                'update_time',
                Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false, 'default' =>Table::TIMESTAMP_INIT_UPDATE],
                'Modification Time'
            )
        
            ->setComment('Brand Table');
            $installer->getConnection()->createTable($table);
        }
    //ck_brand_product
        $table = $installer->getConnection()->newTable(
            $installer->getTable('ck_brand_product')
        )->addColumn(
            'brand_id',
            Table::TYPE_INTEGER,
            null,
            ['nullable' => false, 'primary' => true],
            'Brand ID'
        )->addColumn(
            'product_id',
            Table::TYPE_SMALLINT,
            null,
            ['unsigned' => true, 'nullable' => false, 'primary' => true],
            'Product ID'
        )->addColumn(
            'position',
            Table::TYPE_INTEGER,
            11,
            ['nullable' => true],
            'Position'
        )->setComment(
            'Coderkube Brand To Product Table'
        );
        $installer->getConnection()->createTable($table);
  
        $installer->endSetup();
    }
}
