<?php

use App\Packages\Core\Models\Localization;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class LocalizationMigrationTable extends Migration
{
	const TABLE = 'table_localization';

	/**
	 * Run the migrations.
	 *
	 * @return void
	 */
	public function up()
	{
		Schema::create(self::TABLE, function (Blueprint $table) {
			$table->increments('id');
			$table->string('code')->nullable();
			$table->string('title')->nullable();
			$table->string('script')->nullable();
			$table->string('native')->nullable();
			$table->string('regional')->nullable();
			$table->timestamps();
		});

		collect([
			['code' => 'lv', 'title' => 'Latvian', 'script' => 'Latn', 'native' => 'Latviešu', 'regional' => 'lv_LV'],
			['code' => 'ru', 'title' => 'Russian', 'script' => 'Cyrl', 'native' => 'Русский', 'regional' => 'ru_RU'],
			['code' => 'en', 'title' => 'English', 'script' => 'Latn', 'native' => 'English', 'regional' => 'en_GB'],
		])->each(function($locale) {
			$localization = new Localization();
			$localization->fill($locale);
			$localization->save();
		});
	}

	/**
	 * Reverse the migrations.
	 *
	 * @return void
	 */
	public function down()
	{
		Schema::drop(self::TABLE);
	}
}
