<?php

namespace Database\Seeders;

// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Hash;
use App\Models\Master\Group;
use App\Models\Master\Instansi;
use App\Models\User;

class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     */
    public function run(): void
    {
        // \App\Models\User::factory(10)->create();

        // \App\Models\User::factory()->create([
        //     'name' => 'Test User',
        //     'email' => 'test@example.com',
        // ]);

        $group = [
            ['name' => 'Administrator','alias' => 'administrator'],
            ['name' => 'Dinas','alias' => 'dinas'],
        ];

        foreach($group as $valGroup){
            Group::updateOrCreate([
                'name' => $valGroup['name'],
                'alias' => $valGroup['alias'],
            ],[
                'name' => $valGroup['name'],
                'alias' => $valGroup['alias'],
                'status' => 1,
            ]);
        }
        $instansi = [
            ['type' => 'Biro' , 'name' => 'Biro Kepala Daerah'],
            ['type' => 'Biro' , 'name' => 'Biro Kerjasama Daerah'],
            ['type' => 'Biro' , 'name' => 'Biro Kesejahteraan Sosial'],
            ['type' => 'Biro' , 'name' => 'Biro Organisasi Dan Reformasi Birokrasi'],
            ['type' => 'Biro' , 'name' => 'Biro Pembangunan Dan Lingkungan Hidup'],
            ['type' => 'Biro' , 'name' => 'Biro Pemerintahan'],
            ['type' => 'Biro' , 'name' => 'Biro Pendidikan Dan Mental Spiritual'],
            ['type' => 'Biro' , 'name' => 'Biro Perekonomian Dan Keuangan'],
            ['type' => 'Biro' , 'name' => 'Biro Umum dan Administrasi Sekretariat Daerah'],
            ['type' => 'Biro' , 'name' => 'Biro Hukum'],
            ['type' => 'Badan' , 'name' => 'Badan Perencanaan Pembangunan Daerah (Bappeda)'],
            ['type' => 'Badan' , 'name' => 'Badan Pengelola Keuangan Daerah (BPKD)'],
            ['type' => 'Badan' , 'name' => 'Badan Pengelola Aset Daerah (BPAD)'],
            ['type' => 'Badan' , 'name' => 'Badan Pendapatan Daerah (Bapenda)'],
            ['type' => 'Badan' , 'name' => 'Badan Kesatuan Bangsa dan Politik (Kesbangpol)'],
            ['type' => 'Badan' , 'name' => 'Badan Pembinaan Badan Usaha Milik Daerah (BPBUMD)'],
            ['type' => 'Badan' , 'name' => 'Badan Kepegawaian Daerah (BKD)'],
            ['type' => 'Badan' , 'name' => 'Badan Pengembangan Sumber Daya Manusia (BPSDM)'],
            ['type' => 'Badan' , 'name' => 'Badan Penanggulangan Bencana Daerah (BPBD)'],
            ['type' => 'Badan' , 'name' => 'Badan Pelayanan Pengadaan Barang dan Jasa (BPPBJ)'],
            ['type' => 'Deputi' , 'name' => 'Deputi Bidang Tata Ruang dan Lingkungan Hidup'],
            ['type' => 'Deputi' , 'name' => 'Deputi Bidang Pengendalian Kependudukan dan Permukiman'],
            ['type' => 'Deputi' , 'name' => 'Deputi Bidang Industri, Perdagangan dan Transportasi'],
            ['type' => 'Deputi' , 'name' => 'Deputi Bidang Budaya dan Pariwisata'],
            ['type' => 'Dinas' , 'name' => 'Dinas Pendidikan'],
            ['type' => 'Dinas' , 'name' => 'Dinas Kesehatan'],
            ['type' => 'Dinas' , 'name' => 'Dinas Bina Marga'],
            ['type' => 'Dinas' , 'name' => 'Dinas Sumber Daya Air'],
            ['type' => 'Dinas' , 'name' => 'Dinas Cipta Karya, Tata Ruang dan Pertanahan'],
            ['type' => 'Dinas' , 'name' => 'Dinas Perumahan Rakyat dan Kawasan Permukiman'],
            ['type' => 'Dinas' , 'name' => 'Dinas Penanggulangan Kebakaran dan Penyelamatan'],
            ['type' => 'Dinas' , 'name' => 'Dinas Sosial'],
            ['type' => 'Dinas' , 'name' => 'Dinas Tenaga Kerja, Transmigrasi dan Energi'],
            ['type' => 'Dinas' , 'name' => 'Dinas Pemberdayaan, Perlindungan Anak dan Pengendalian Penduduk'],
            ['type' => 'Dinas' , 'name' => 'Dinas Ketahanan Pangan, Kelautan dan Pertanian'],
            ['type' => 'Dinas' , 'name' => 'Dinas Lingkungan Hidup'],
            ['type' => 'Dinas' , 'name' => 'Dinas Kependudukan dan Pencatatan Sipil'],
            ['type' => 'Dinas' , 'name' => 'Dinas Perhubungan'],
            ['type' => 'Dinas' , 'name' => 'Dinas Komunikasi, Informatika dan Statistik'],
            ['type' => 'Dinas' , 'name' => 'Dinas Perindustrian, Perdagangan, Koperasi dan Usaha Kecil Menengah'],
            ['type' => 'Dinas' , 'name' => 'Dinas Penanaman Modal dan Pelayanan Terpadu Satu Pintu'],
            ['type' => 'Dinas' , 'name' => 'Dinas Pemuda dan Olahraga'],
            ['type' => 'Dinas' , 'name' => 'Dinas Pariwisata dan Ekonomi Kreatif'],
            ['type' => 'Dinas' , 'name' => 'Dinas Perpustakaan dan Kearsipan'],
            ['type' => 'Dinas' , 'name' => 'Dinas Pertamanan dan Hutan Kota'],
            ['type' => 'Dinas' , 'name' => 'Dinas Kebudayaan'],
        ];

        foreach($instansi as $dataInstansi){
            Instansi::updateOrCreate([
                'parent' => $dataInstansi['type'],
                'name' => $dataInstansi['name'],
            ],[
                'parent' => $dataInstansi['type'],
                'name' => $dataInstansi['name'],
            ]);
        }

        User::updateOrCreate([
            'name'          => 'Administrator',
            'username'      => 'administrator',
            'email'         => 'adminadiwiyata@dlh.go.id',
        ],[
            'name'          => 'Administrator',
            'username'      => 'administrator',
            'email'         => 'admindikplhd@dlh.go.id',
            'ms_group_id'   => '1',
            'ms_instansi_id'   => '1',
            'password'      => Hash::make('##Dikplhd2025'),
        ]);

        
        $menu = [
            [
                'parent_id'     => '0',
                'title'         => 'Master Data',
                'module'        => 'modules.master.*',
                'url'           => '#',
                'menu_type'     => 'sidebar',
                'menu_icon'     => 'ri-database-2-line',
                'ordering'      =>	'5',
                'status'        => 'true',
                'created_by'    => '1',
                'updated_by'    => '0'
            ],[
                'parent_id'     => '0',
                'title'         => 'User & Hak Akses',
                'module'        => 'modules.management.*',
                'url'           => '#',
                'menu_type'     => 'sidebar',
                'menu_icon'     => 'ri-database-2-line', 
                'ordering'      =>	'5',
                'status'        => 'true',
                'created_by'    => '1',
                'updated_by'    => '0'
            ],[
                'parent_id'      => '2',
                'title'          => 'Data Users',
                'module'         => 'modules.management.user.*',
                'url'            => 'management/user',
                'menu_type'      => 'sidebar',
                'menu_icon'      => 'ri-user-line', 
                'ordering'       => '1',
                'status'         => 'true',
                'created_by'     => '1',
                'updated_by'     => '0'
            ],[
                'parent_id'      => '2',
                'title'          => 'Data Role User',
                'module'         => 'modules.management.role.*',
                'url'           => 'management/role',
                'menu_type'      => 'sidebar',
                'menu_icon'      => 'ri-share-line', 
                'ordering'       =>	'3',
                'status'         => 'true',
                'created_by'     => '1',
                'updated_by'     => '0'
            ],[
                'parent_id'      => '1',
                'title'          => 'Data Instansi',
                'module'         => 'modules.instansi.*',
                'url'           => 'master/instansi',
                'menu_type'      => 'sidebar',
                'menu_icon'      => 'ri-home-line', 
                'ordering'       =>'1',
                'status'         => 'true',
                'created_by'     => '1',
                'updated_by'     => '0'
            ],[
                'parent_id'      => '0',
                'title'          => 'Open Data',
                'module'         => 'modules.opendata.*',
                'url'           => '#',
                'menu_type'      => 'sidebar',
                'menu_icon'      => 'ri-database-2-line', 
                'ordering'       =>	'1',
                'status'         => 'true',
                'created_by'     => '1',
                'updated_by'     => '0'
            ],[
                'parent_id'      => '6',
                'title'          => 'Dataset',
                'module'         => 'modules.opendata.dataset.*',
                'url'            => 'opendata/dataset',
                'menu_type'      => 'sidebar',
                'menu_icon'      => 'ri-database-2-line', 
                'ordering'       =>	'1',
                'status'         => 'true',
                'created_by'     => '1',
                'updated_by'     => '0'
            ],
        ];

        foreach($menu as $dataMenu){
            Menu::updateOrCreate([
                'parent_id'      => $dataMenu['parent_id'],
                'title'          => $dataMenu['title'],
                'module'         => $dataMenu['module'],
                'url'            => $dataMenu['url'],
                'menu_type'      => $dataMenu['menu_type'],
                'menu_icon'      => $dataMenu['menu_icon'],
                'ordering'       =>	$dataMenu['ordering'],
                'status'         => $dataMenu['status'],
                'created_by'     => $dataMenu['created_by'],
                'updated_by'     => $dataMenu['updated_by'],
            ],[
                'parent_id'      => $dataMenu['parent_id'],
                'title'          => $dataMenu['title'],
                'module'         => $dataMenu['module'],
                'url'            => $dataMenu['url'],
                'menu_type'      => $dataMenu['menu_type'],
                'menu_icon'      => $dataMenu['menu_icon'],
                'ordering'       =>	$dataMenu['ordering'],
                'status'         => $dataMenu['status'],
                'created_by'     => $dataMenu['created_by'],
                'updated_by'     => $dataMenu['updated_by'],
            ]);
        }
    

        
    }
}
