<?php

/*
 * Created on Mon Mar 25 2019
 * HomePage: http://dcforo.com/
 * Email: datdaik000@gmail.com
 * Blog: https://fb.com/dcstylexf/
 * Copyright (c) 2019 D.C Style XenForo -  All Rights Reserved
 */

namespace DC\ThreadThumbnail;

use XF\Db\Schema\Alter;
use XF\Db\Schema\Create;

use XF\AddOn\AbstractSetup;
use XF\AddOn\StepRunnerInstallTrait;
use XF\AddOn\StepRunnerUninstallTrait;
use XF\AddOn\StepRunnerUpgradeTrait;

class Setup extends AbstractSetup
{
	use StepRunnerInstallTrait;
	use StepRunnerUpgradeTrait;
	use StepRunnerUninstallTrait;

	public function installStep1()
	{
		$this->schemaManager()->alterTable('xf_thread', function(Alter $table)
		{
			$table->addColumn('DC_ThreadThumbnail_thumbCustom', 	'tinyint')->setDefault(0);
			$table->addColumn('DC_ThreadThumbnail_thumbUrl', 		'varchar', 255)->setDefault('');
			$table->addColumn('DC_ThreadThumbnail_threadCover', 	'tinyint')->setDefault(0);
			$table->addColumn('DC_ThreadThumbnail_threadCoverUrl', 	'varchar', 255)->setDefault('');
			$table->addColumn('DC_ThreadThumbnail_threadVideoID', 'varchar', 255)->setDefault('');
			$table->addColumn('DC_ThreadThumbnail_threadVideoSite', 'varchar', 255)->setDefault('');
			$table->addColumn('DC_ThreadThumbnail_threadVideoUrl', 	'varchar', 255)->setDefault('');
			$table->addColumn('DC_ThreadThumbnail_tempThumbUrl', 'varchar', 255)->setDefault('');
			$table->addColumn('DC_ThreadThumbnail_tempImageUrl', 'varchar', 255)->setDefault('');
		});
	}

	public function upgrade1060170Step1()
	{
		$this->installStep1();
	}

	public function upgrade1060270Step1()
	{
		$this->schemaManager()->alterTable('xf_thread', function(Alter $table)
		{
			$table->changeColumn('DC_ThreadThumbnail_thumbUrl')->length(500);
			$table->changeColumn('DC_ThreadThumbnail_threadCoverUrl')->length(500);
			$table->changeColumn('DC_ThreadThumbnail_threadVideoUrl')->length(500);
			$table->changeColumn('DC_ThreadThumbnail_tempThumbUrl')->length(500);
			$table->changeColumn('DC_ThreadThumbnail_tempImageUrl')->length(500);
		});
	}

	public function uninstallStep1()
	{
		$this->schemaManager()->alterTable('xf_thread', function(Alter $table)
		{
			$table->dropColumns('DC_ThreadThumbnail_thumbCustom');
			$table->dropColumns('DC_ThreadThumbnail_thumbUrl');
			$table->dropColumns('DC_ThreadThumbnail_threadCover');
			$table->dropColumns('DC_ThreadThumbnail_threadCoverUrl');
			$table->dropColumns('DC_ThreadThumbnail_threadVideoSite');
			$table->dropColumns('DC_ThreadThumbnail_threadVideoID');
			$table->dropColumns('DC_ThreadThumbnail_threadVideoUrl');
		});
	}
}