<?php

namespace Modules\Employee\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Modules\Core\Database\Seeders\Traits\DisableForeignKeys;
use Modules\Core\Enums\AddressTypeEnum;
use Modules\Core\Enums\StatusEnum;
use Modules\Employee\Models\Branch;
use Modules\Employee\Models\Country;
use Modules\Settings\Models\Address;

class BranchSeeder extends Seeder
{
    use DisableForeignKeys, WithoutModelEvents;

    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $this->disableForeignKeys();

        Address::where('addressable_type', Branch::class)->delete();

        Branch::truncate();

        $branch = Branch::create([
            'name'   => 'Bangladesh Thalassaemia Samity',
            'status' => StatusEnum::ACTIVE,
        ]);

        $bangladesh = Country::where('code', 'BD')->first();

        $branch->presentAddress()->create([
            'type'        => AddressTypeEnum::PRESENT,
            'address'     => '25A/25B Green Road, Dhaka',
            'postal_code' => '1205',
            'country_id'  => $bangladesh?->id,
        ]);

        $this->enableForeignKeys();
    }
}
