<?php

namespace Database\Seeders;

use App\Models\BillingAddress;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Artisan;

class DatabaseSeeder extends Seeder
{

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(RoleTableSeeder::class);
        $this->call(PermissionTableSeeder::class);
        $this->call(LanguageTableSeeder::class);
        $this->call(SettingsTableSeeder::class);
        $this->call(TicketCategorySeeder::class);
        $this->call(PageTableSeeder::class);
        $this->call(ProductCategoriesTableSeeder::class);

        if (in_array(env('APP_ENV'), ['local', 'demo'])) {
            $this->call(ProductTableSeeder::class);

            // Create admin user
            $user = User::create([
                'first_name' => 'Site',
                'last_name' => 'Admin',
                'email' => 'admin@admin.com',
                'password' => bcrypt('123'),
                'email_verified_at' => Carbon::now(),
            ]);
            $user->roles()->sync([1]);

            BillingAddress::create([
                'user_id' => $user->id,
                'first_name' => 'Site',
                'last_name' => 'Admin',
                'company_name' => 'ChargePanda LLC',
                'address' => 'Test Street, Test Road, Test Town',
                'city' => 'Test City',
                'state_id' => 2728,
                'zip' => '12345',
                'country_id' => 166,
                'phone_number' => '0300-1234567',
            ]);

            // Demo seeder: creates 10 customer users + all demo data
            $this->call(DemoSeeder::class);
        }

        $this->call(MenuTableSeeder::class);


        Artisan::call('cache:clear');
    }

}
