<?php

namespace Database\Seeders;

use App\Models\District;
use App\Models\Province;
use Illuminate\Database\Seeder;

class ProvinceDistrictSeeder extends Seeder
{
    public function run(): void
    {
        $provincesData = [
            'MPT' => ['name' => 'Maputo Cidade', 'districts' => ['KaMpfumo', 'Nlhamankulu', 'KaMaxakeni', 'KaMubukwana', 'KaTembe', 'KaNyaka']],
            'MPV' => ['name' => 'Maputo Província', 'districts' => ['Matola', 'Boane', 'Marracuene', 'Moamba', 'Namaacha', 'Magude', 'Manhiça', 'Matutuíne']],
            'GZ'  => ['name' => 'Gaza', 'districts' => ['Xai-Xai', 'Bilene', 'Chibuto', 'Chicualacuala', 'Chigubo', 'Chókwè', 'Guijá', 'Limpopo', 'Mabalane', 'Mandlakazi', 'Massangena', 'Massingir']],
            'INH' => ['name' => 'Inhambane', 'districts' => ['Inhambane', 'Funhalouro', 'Govuro', 'Homoíne', 'Inharrime', 'Inhassoro', 'Jangamo', 'Mabote', 'Massinga', 'Maxixe', 'Morrumbene', 'Panda', 'Vilankulo', 'Zavala']],
            'MNS' => ['name' => 'Manica', 'districts' => ['Chimoio', 'Báruè', 'Gondola', 'Guro', 'Macate', 'Machaze', 'Manica', 'Mossurize', 'Sussundenga', 'Tambara']],
            'SFX' => ['name' => 'Sofala', 'districts' => ['Beira', 'Búzi', 'Caia', 'Chemba', 'Cheringoma', 'Chibabava', 'Dondo', 'Gorongosa', 'Machanga', 'Marínguè', 'Muanza', 'Nhamatanda']],
            'TET' => ['name' => 'Tete', 'districts' => ['Tete', 'Angónia', 'Cahora-Bassa', 'Changara', 'Chifunde', 'Chiuta', 'Dôa', 'Macanga', 'Marávia', 'Moatize', 'Mutarara', 'Tsangano', 'Zumbo']],
            'ZBZ' => ['name' => 'Zambézia', 'districts' => ['Quelimane', 'Alto Molocué', 'Chinde', 'Gile', 'Guruè', 'Ile', 'Inhassunge', 'Luabo', 'Lugela', 'Maganja da Costa', 'Milange', 'Mocuba', 'Mopeia', 'Morrumbala', 'Namacurra', 'Namarroi', 'Nicoadala', 'Pebane']],
            'NPL' => ['name' => 'Nampula', 'districts' => ['Nampula', 'Angoche', 'Eráti', 'Lalaua', 'Larde', 'Liupo', 'Malema', 'Meconta', 'Mecubúri', 'Memba', 'Mogincual', 'Mogovolas', 'Moma', 'Monapo', 'Mossuril', 'Muecate', 'Murrupula', 'Nacala', 'Nacala-a-Velha', 'Nacarôa', 'Rapale', 'Ribaué']],
            'CAB' => ['name' => 'Cabo Delgado', 'districts' => ['Pemba', 'Ancuabe', 'Balama', 'Chiúre', 'Ibo', 'Macomia', 'Mecúfi', 'Meluco', 'Mocímboa da Praia', 'Montepuez', 'Mueda', 'Muidumbe', 'Namuno', 'Nangade', 'Palma', 'Quissanga']],
            'NAS' => ['name' => 'Niassa', 'districts' => ['Lichinga', 'Chimbonila', 'Cuamba', 'Lago', 'Majune', 'Mandimba', 'Marrupa', 'Maúa', 'Mavago', 'Mecanhelas', 'Mecula', 'Metarica', 'Muembe', 'N\'Gauma', 'Ngapa', 'Sanga']],
        ];

        foreach ($provincesData as $code => $data) {
            $province = Province::firstOrCreate(
                ['code' => $code],
                ['name' => $data['name']]
            );
            foreach ($data['districts'] as $districtName) {
                District::firstOrCreate(
                    ['province_id' => $province->id, 'name' => $districtName]
                );
            }
        }
    }
}
