<?php

namespace Database\Factories;

use App\Models\Voter;
use Illuminate\Database\Eloquent\Factories\Factory;

class VoterFactory extends Factory
{
    protected $model = Voter::class;

    public function definition(): array
    {
        $bnFirst = ['আবদুল', 'মোঃ', 'সালমা', 'আয়েশা', 'রুবিনা', 'কামাল', 'জসিম', 'শাহানা', 'নাসরিন', 'মোস্তাফিজ'];
        $bnLast  = ['করিম', 'রহিম', 'হোসেন', 'ইসলাম', 'চৌধুরী', 'মিয়া', 'উদ্দিন', 'সুলতানা', 'খাতুন', 'রহমান'];

        $enFirst = ['Abdul', 'Md', 'Salma', 'Ayesha', 'Rubina', 'Kamal', 'Jasim', 'Shahana', 'Nasrin', 'Mostafiz'];
        $enLast  = ['Karim', 'Rahim', 'Hossain', 'Islam', 'Chowdhury', 'Miah', 'Uddin', 'Sultana', 'Khatun', 'Rahman'];

        $occupationsBn = ['শিক্ষক', 'ব্যবসায়ী', 'চাকরিজীবী', 'কৃষক', 'ডাক্তার', 'ইঞ্জিনিয়ার', 'ছাত্র', 'গৃহিণী', 'শ্রমিক'];
        $occupationsEn = ['Teacher', 'Business', 'Service', 'Farmer', 'Doctor', 'Engineer', 'Student', 'Homemaker', 'Worker'];

        $i = $this->faker->unique()->numberBetween(1, 999999);

        // Serial number (string/number — adjust if your DB type is string)
        $serialNo = str_pad((string) $i, 6, '0', STR_PAD_LEFT);

        // NID EN (10-17 digits in BD, but you can choose; using 10 for simplicity)
        $nidEn = (string) $this->faker->unique()->numberBetween(1000000000, 9999999999);
        $nidBn = $this->enToBnDigits($nidEn);

        $nameBn = $this->faker->randomElement($bnFirst) . ' ' . $this->faker->randomElement($bnLast);
        $nameEn = $this->faker->randomElement($enFirst) . ' ' . $this->faker->randomElement($enLast);

        $fatherBn = 'পিতা ' . $this->faker->randomElement($bnLast);
        $motherBn = 'মাতা ' . $this->faker->randomElement($bnLast);

        $districts = ['ঢাকা', 'চট্টগ্রাম', 'খুলনা', 'রাজশাহী', 'সিলেট', 'বরিশাল', 'রংপুর', 'ময়মনসিংহ'];
        $upazilas  = ['সদর', 'কেরানীগঞ্জ', 'সাভার', 'পটিয়া', 'ডুমুরিয়া', 'বাগমারা', 'বালাগঞ্জ', 'গৌরীপুর'];

        $district = $this->faker->randomElement($districts);
        $upazila  = $this->faker->randomElement($upazilas);

        $wardNo = (string) $this->faker->numberBetween(1, 30);
        $areaCode = (string) $this->faker->numberBetween(1000, 9999);

        $address = $upazila . ', ' . $district . ', বাংলাদেশ';

        // Occupation as combined BN/EN or just BN depending on your schema
        $occupation = $occupationsBn[array_rand($occupationsBn)] . ' / ' . $occupationsEn[array_rand($occupationsEn)];

        return [
            'serial_no' => $serialNo,

            'name_bn' => $nameBn,
            'name_en' => $nameEn,

            'nid_bn' => $nidBn,
            'nid_en' => $nidEn,

            'father_name' => $fatherBn,
            'mother_name' => $motherBn,

            'date_of_birth' => $this->faker->dateTimeBetween('-60 years', '-18 years')->format('Y-m-d'),

            'occupation' => $occupation,
            'address' => $address,

            'area_code' => $areaCode,
            'ward_no' => $wardNo,

            'upazila' => $upazila,
            'district' => $district,
        ];
    }

    private function enToBnDigits(string $value): string
    {
        return strtr($value, [
            '0' => '০','1' => '১','2' => '২','3' => '৩','4' => '৪',
            '5' => '৫','6' => '৬','7' => '৭','8' => '৮','9' => '৯',
        ]);
    }
}
