<?php

declare(strict_types=1);

namespace Database\Seeders;

use App\Models\Expert;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
use Mortezaa97\Regions\Models\County;
use Mortezaa97\Regions\Models\Province;

class ExpertsTableSeeder extends Seeder
{
    public function run(): void
    {
        $adminId = User::role('admin')->first()?->id;
        $province = Province::first();
        $county = County::where('province_id', $province?->id)->first();

        $expertUser = User::firstOrCreate(
            ['cellphone' => '09121111111'],
            [
                'first_name' => 'کارشناس',
                'last_name' => 'دامپزشکی',
                'email' => 'expert@rievo.ir',
                'password' => Hash::make('123456789'),
            ]
        );

        if (! $expertUser->hasRole('user')) {
            $expertUser->assignRole('user');
        }

        Expert::firstOrCreate(
            ['user_id' => $expertUser->id],
            [
                'brand_name' => 'کلینیک دامپزشکی نمونه',
                'work_email' => 'clinic@example.com',
                'work_phone' => '021-87654321',
                'main_category' => 'دامپزشکی',
                'sub_category' => 'دام بزرگ',
                'species_type' => 'گاو، گوسفند، بز',
                'work_province_id' => $province?->id,
                'work_county_id' => $county?->id,
                'work_address' => 'خیابان اصلی، پلاک ۱۰',
                'work_latitude' => 35.6892,
                'work_longitude' => 51.3890,
                'created_by' => $adminId,
                'updated_by' => $adminId,
            ]
        );
    }
}
