<?php

namespace Database\Seeders;

use App\Models\LocalizationManagement\City;
use App\Models\LocalizationManagement\Country;
use App\Models\LocalizationManagement\Quarter;
use App\Models\LocalizationManagement\State;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;

class InstallLocalizationTablesSeeder extends Seeder {
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run() {
        $sqlFIle = "localization-data.sql";

        $queries = Storage::disk("assets")->get($sqlFIle);

        DB::unprepared("set foreign_key_checks=0");
        DB::table((new Quarter)->getTable())->truncate();
        DB::table((new City)->getTable())->truncate();
        DB::table((new State)->getTable())->truncate();
        DB::table((new Country)->getTable())->truncate();

        $queries = preg_replace("/[\r]*/","",$queries);

        DB::unprepared($queries);

        echo "All Localization tables  Installed !!!\n\n";

//        $db = [
//            'host' => config('database.connections.mysql.host'),
//            'database' => config('database.connections.mysql.database'),
//            'username' => config('database.connections.mysql.username'),
//            'password' => config('database.connections.mysql.password'),
//        ];
//
//        exec("mysql --user={$db['username']} --password={$db['password']} --host={$db['host']} --database={$db['database']} < $sqlFIle");
    }
}
