<?php


namespace App\Console\Commands\Install\Updates;


use App\Models\UserManagement\Admin;
use Database\Seeders\AdminSeeder;
use Database\Seeders\InstallLocalizationTablesSeeder;
use Database\Seeders\PaymentMethodSeeder;
use Database\Seeders\PermissionSeeder;
use Database\Seeders\RoleSeeder;
use Database\Seeders\SettingSeeder;
use Database\Seeders\StatusSeeder;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use App\Models\SecurityManagement\Permission;
use App\Models\SecurityManagement\Role;
use App\Models\UserManagement\User;
use Illuminate\Support\Facades\DB;
use function Symfony\Component\Console\Helper\fillCells;

class InstallUpdateV2Command extends Command{

    protected $signature = 'install:updates-v2';
    protected $description = "";

    public function handle(){


       try{
           // $tableNames = config('permission.table_names');
            DB::unprepared("set foreign_key_checks=0");

            $seeds = [
                \SettingSeeder::class,
                \PermissionSeeder::class,
                \RoleSeeder::class,
                \PaymentMethodSeeder::class,
                \StatusSeeder::class,
                \InstallLocalizationTablesSeeder::class,
                \AdminSeeder::class,
            ];

            if (filled($seeds)){
                foreach ($seeds as $seed) {
                    Artisan::call("db:seed" , ['--class' => $seed ]);
                }
            }
            $migrations = [
               "database/migrations/2024_02_21_100404_add_field_to_payment_method_table.php",
            ];

            if (filled($migrations)){
                foreach ($migrations as $migration) {
                    Artisan::call("migrate" , ['--path' => $migration ]);
                }
            }

           // DB::commit();
       }
       catch(\Exception $e){
          //DB::rollback();
          echo($e->getMessage()." | Line : ".$e->getFile()."\n\n\n");
       }


    }
}
