<?php

namespace Database\Seeders;

use App\Models\Role;
use App\Models\User;
use Illuminate\Support\Str;
use App\Models\VendorAccount;
use App\Models\ShopInfo;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $admin = Role::updateOrCreate(['name' => 'Admin', 'slug' => 'admin']);
        $adminUser = User::updateOrCreate([
            'role_id' => $admin->id,
            'desig' => 1,
            'name' => 'Admin',
            'username' => 'admin',
            'email' => 'admin@gmail.com',
            'phone' => '01721600688',
            'is_approved' => true,
            'avatar' => '',
            'joining_date' => date('Y-m-d'),
            'joining_month' => date('F'),
            'joining_year' => date('Y'),
            'email_verified_at' => now(),
            'password' => Hash::make('12345678'),
            'remember_token' => Str::random(10)
        ]);

        VendorAccount::updateOrCreate([
            'vendor_id' => $adminUser->id
        ], [
            'balance' => 0,
            'pending_amount' => 0
        ]);

        ShopInfo::updateOrCreate([
            'user_id' => $adminUser->id,
            'is_admin' => 1
        ], [
            'slug' => 'admin-shop',
            'name' => 'Admin Shop',
            'address' => 'Admin Address',
            'url' => 'admin-shop-url',
            'bank_account' => '123456789',
            'bank_name' => 'Admin Bank',
            'holder_name' => 'Admin Holder',
            'branch_name' => 'Admin Branch',
            'routing' => '123456',
            'profile' => '',
            'cover_photo' => '',
            'description' => 'Admin Shop Description',
            'commission' => 0,
            'shop_mobile' => '01721600688',
            'shop_whatsapp' => '01721600688',
            'shop_telegram' => 'admin_telegram',
            'shop_messenger' => 'admin_messenger',
            'shop_imo' => 'admin_imo',
            'shop_fb' => 'admin_fb',
            'shop_linkedin' => 'admin_linkedin',
            'shop_twitter' => 'admin_twitter'
        ]);

        $vendor = Role::updateOrCreate(['name' => 'Vendor', 'slug' => 'vendor']);
        $vendorUser = User::updateOrCreate([
            'role_id' => $vendor->id,
            'desig' => NULL,
            'refer' => 2,
            'name' => 'Vendor',
            'username' => 'vendor',
            'email' => 'vendor@gmail.com',
            'phone' => '01303851066',
            'is_approved' => true,
            'joining_date' => date('Y-m-d'),
            'joining_month' => date('F'),
            'joining_year' => date('Y'),
            'email_verified_at' => now(),
            'password' => Hash::make('12345678'),
            'remember_token' => Str::random(10)
        ]);

        VendorAccount::updateOrCreate([
            'vendor_id' => $vendorUser->id
        ], [
            'balance' => 0,
            'pending_amount' => 0
        ]);

        ShopInfo::updateOrCreate([
            'user_id' => $vendorUser->id,
            'is_admin' => 0
        ], [
            'slug' => 'vendor-shop',
            'name' => 'Vendor Shop',
            'address' => 'Vendor Address',
            'url' => 'vendor-shop-url',
            'bank_account' => '987654321',
            'bank_name' => 'Vendor Bank',
            'holder_name' => 'Vendor Holder',
            'branch_name' => 'Vendor Branch',
            'routing' => '654321',
            'profile' => '',
            'cover_photo' => '',
            'description' => 'Vendor Shop Description',
            'commission' => 0,
            'shop_mobile' => '01303851066',
            'shop_whatsapp' => '01303851066',
            'shop_telegram' => 'vendor_telegram',
            'shop_messenger' => 'vendor_messenger',
            'shop_imo' => 'vendor_imo',
            'shop_fb' => 'vendor_fb',
            'shop_linkedin' => 'vendor_linkedin',
            'shop_twitter' => 'vendor_twitter'
        ]);
    }
}
