<?php


namespace App\Console\Commands\Install;


use App\Models\UserManagement\Admin;
use Database\Seeders\AdminSeeder;
use Database\Seeders\InstallLocalizationTablesSeeder;
use Database\Seeders\PaymentMethodSeeder;
use Database\Seeders\PermissionSeeder;
use Database\Seeders\PointOfSalesSeeder;
use Database\Seeders\RoleSeeder;
use Database\Seeders\SettingSeeder;
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 InstallAppCommand extends Command{

    protected $signature = 'install:app';
    protected $description = "";

    public function handle(){


//        DB::beginTransaction();

//       try{
            DB::unprepared("set foreign_key_checks=0");

//            dd("ici");

            Artisan::call("migrate:fresh");
           echo strtoupper("All Tables created in database.\n\n");

            $seeds = [

                \SettingSeeder::class,
                \PermissionSeeder::class,
                \RoleSeeder::class,
                \AdminSeeder::class,
                \PaymentMethodSeeder::class,
                \StatusSeeder::class,
                \InstallLocalizationTablesSeeder::class,
            ];

            if (filled($seeds)){
                foreach ($seeds as $seed) {
                    Artisan::call("db:seed" , ['--class' => $seed ]);
                }
            }

            echo strtoupper("All Data installed in Database \n\n");
//       }
//       catch(\Exception $e){
//          DB::rollback();
          //dd($e);
          //echo($e->getMessage()." | File : ".$e->getFile()."\n\n\n");
//       }


    }
}
