<?php

namespace PortalPeople\AuthRedirect\Setup\Patch\Schema;

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

class NewTable implements SchemaPatchInterface
{
    private $moduleDataSetup;

    public function __construct(
        ModuleDataSetupInterface $moduleDataSetup
    ) {
        $this->moduleDataSetup = $moduleDataSetup;
    }

    public static function getDependencies()
    {
        return [];
    }

    public function apply()
    {
        $installer = $this->moduleDataSetup;
        $installer->startSetup();

        $tableName = $installer->getTable('portalpeople_login_attempt_logger');
        if (!$installer->getConnection()->isTableExists($tableName)) {
            $table = $installer->getConnection()->newTable(
                $tableName
            )->addColumn(
                'entity_id',
                Table::TYPE_INTEGER,
                null,
                ['identity' => true, 'nullable' => false, 'primary' => true],
                'Entity ID'
            )->addColumn(
                'email',
                Table::TYPE_TEXT,
                255,
                ['nullable' => false],
                'Email'
            )->addColumn(
                'ip_address',
                Table::TYPE_TEXT,
                255,
                ['nullable' => false],
                'IP Address'
            )->addColumn(
                'was_successful',
                Table::TYPE_BOOLEAN,
                null,
                ['nullable' => false],
                'Was Successful'
            )->addColumn(
                'attempted_at',
                Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false],
                'Attempted At'
            )->setComment('Login Attempt Table');

            $installer->getConnection()->createTable($table);
        }

        $installer->endSetup();
    }

    public function revert()
    {
        // Implement revert if necessary
    }

    public function getAliases()
    {
        return [];
    }
}