<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class SeedQuranSurahs extends Migration
{
    public function up()
    {
        // Cek apakah sudah ada data
        $count = $this->db->table('quran_surahs')->countAllResults();
        if ($count >= 114) {
            return; // Sudah ada data, skip
        }

        $surahs = [
            [1,  'الفَاتِحَة',  'Al-Fatihah',    'Pembukaan',          7,   1,  'Makkiyah'],
            [2,  'البَقَرَة',   'Al-Baqarah',     'Sapi Betina',        286, 1,  'Madaniyah'],
            [3,  'آل عِمرَان', 'Ali \'Imran',    'Keluarga Imran',     200, 3,  'Madaniyah'],
            [4,  'النِّسَاء',  'An-Nisa\'',      'Wanita',             176, 4,  'Madaniyah'],
            [5,  'المَائِدَة', 'Al-Ma\'idah',    'Hidangan',           120, 6,  'Madaniyah'],
            [6,  'الأَنعَام',  'Al-An\'am',      'Binatang Ternak',    165, 7,  'Makkiyah'],
            [7,  'الأَعرَاف',  'Al-A\'raf',      'Tempat Tertinggi',   206, 8,  'Makkiyah'],
            [8,  'الأَنفَال',  'Al-Anfal',       'Rampasan Perang',    75,  9,  'Madaniyah'],
            [9,  'التَّوبَة',  'At-Tawbah',      'Pengampunan',        129, 10, 'Madaniyah'],
            [10, 'يُونُس',     'Yunus',          'Nabi Yunus',         109, 11, 'Makkiyah'],
            [11, 'هُود',       'Hud',            'Nabi Hud',           123, 11, 'Makkiyah'],
            [12, 'يُوسُف',    'Yusuf',          'Nabi Yusuf',         111, 12, 'Makkiyah'],
            [13, 'الرَّعد',    'Ar-Ra\'d',       'Guruh',              43,  13, 'Madaniyah'],
            [14, 'إِبرَاهِيم', 'Ibrahim',        'Nabi Ibrahim',       52,  13, 'Makkiyah'],
            [15, 'الحِجر',     'Al-Hijr',        'Bukit Batu',         99,  14, 'Makkiyah'],
            [16, 'النَّحل',    'An-Nahl',        'Lebah',              128, 14, 'Makkiyah'],
            [17, 'الإِسرَاء',  'Al-Isra\'',      'Perjalanan Malam',   111, 15, 'Makkiyah'],
            [18, 'الكَهف',     'Al-Kahf',        'Goa',                110, 15, 'Makkiyah'],
            [19, 'مَريَم',     'Maryam',         'Siti Maryam',        98,  16, 'Makkiyah'],
            [20, 'طه',         'Taha',           'Ta Ha',              135, 16, 'Makkiyah'],
            [21, 'الأَنبِيَاء','Al-Anbiya\'',    'Para Nabi',          112, 17, 'Makkiyah'],
            [22, 'الحَج',      'Al-Hajj',        'Haji',               78,  17, 'Madaniyah'],
            [23, 'المُؤمِنُون','Al-Mu\'minun',   'Orang Beriman',      118, 18, 'Makkiyah'],
            [24, 'النُّور',    'An-Nur',         'Cahaya',             64,  18, 'Madaniyah'],
            [25, 'الفُرقَان',  'Al-Furqan',      'Pembeda',            77,  18, 'Makkiyah'],
            [26, 'الشُّعَرَاء','Asy-Syu\'ara\'', 'Para Penyair',       227, 19, 'Makkiyah'],
            [27, 'النَّمل',    'An-Naml',        'Semut',              93,  19, 'Makkiyah'],
            [28, 'القَصَص',    'Al-Qasas',       'Kisah',              88,  20, 'Makkiyah'],
            [29, 'العَنكَبُوت','Al-\'Ankabut',   'Laba-laba',          69,  20, 'Makkiyah'],
            [30, 'الرُّوم',    'Ar-Rum',         'Bangsa Romawi',      60,  21, 'Makkiyah'],
            [31, 'لُقمَان',    'Luqman',         'Luqman',             34,  21, 'Makkiyah'],
            [32, 'السَّجدَة',  'As-Sajdah',      'Sujud',              30,  21, 'Makkiyah'],
            [33, 'الأَحزَاب',  'Al-Ahzab',       'Golongan Bersekutu', 73,  21, 'Madaniyah'],
            [34, 'سَبَأ',      'Saba\'',         'Kaum Saba\'',        54,  22, 'Makkiyah'],
            [35, 'فَاطِر',     'Fatir',          'Pencipta',           45,  22, 'Makkiyah'],
            [36, 'يس',         'Yasin',          'Ya Sin',             83,  22, 'Makkiyah'],
            [37, 'الصَّافَّات', 'As-Saffat',      'Yang Berbaris',      182, 23, 'Makkiyah'],
            [38, 'ص',          'Sad',            'Sad',                88,  23, 'Makkiyah'],
            [39, 'الزُّمَر',   'Az-Zumar',       'Rombongan',          75,  23, 'Makkiyah'],
            [40, 'غَافِر',     'Gafir',          'Yang Maha Pengampun',85,  24, 'Makkiyah'],
            [41, 'فُصِّلَت',   'Fussilat',       'Dijelaskan',         54,  24, 'Makkiyah'],
            [42, 'الشُّورَى',  'Asy-Syura',      'Musyawarah',         53,  25, 'Makkiyah'],
            [43, 'الزُّخرُف',  'Az-Zukhruf',     'Perhiasan',          89,  25, 'Makkiyah'],
            [44, 'الدُّخَان',  'Ad-Dukhan',      'Kabut',              59,  25, 'Makkiyah'],
            [45, 'الجَاثِيَة', 'Al-Jasiyah',     'Yang Berlutut',      37,  25, 'Makkiyah'],
            [46, 'الأَحقَاف',  'Al-Ahqaf',       'Bukit Pasir',        35,  26, 'Makkiyah'],
            [47, 'مُحَمَّد',   'Muhammad',       'Nabi Muhammad',      38,  26, 'Madaniyah'],
            [48, 'الفَتح',     'Al-Fath',        'Kemenangan',         29,  26, 'Madaniyah'],
            [49, 'الحُجُرَات', 'Al-Hujurat',     'Kamar-kamar',        18,  26, 'Madaniyah'],
            [50, 'ق',          'Qaf',            'Qaf',                45,  26, 'Makkiyah'],
            [51, 'الذَّارِيَات','Az-Zariyat',     'Yang Menerbangkan',  60,  26, 'Makkiyah'],
            [52, 'الطُّور',    'At-Tur',         'Bukit Sinai',        49,  27, 'Makkiyah'],
            [53, 'النَّجم',    'An-Najm',        'Bintang',            62,  27, 'Makkiyah'],
            [54, 'القَمَر',    'Al-Qamar',       'Bulan',              55,  27, 'Makkiyah'],
            [55, 'الرَّحمَن',  'Ar-Rahman',      'Yang Maha Pemurah',  78,  27, 'Madaniyah'],
            [56, 'الوَاقِعَة', 'Al-Waqi\'ah',    'Hari Kiamat',        96,  27, 'Makkiyah'],
            [57, 'الحَدِيد',   'Al-Hadid',       'Besi',               29,  27, 'Madaniyah'],
            [58, 'المُجَادِلَة','Al-Mujadilah',   'Wanita yang Mengadu',22,  28, 'Madaniyah'],
            [59, 'الحَشر',     'Al-Hasyr',       'Pengusiran',         24,  28, 'Madaniyah'],
            [60, 'المُمتَحَنَة','Al-Mumtahanah',  'Wanita yang Diuji',  13,  28, 'Madaniyah'],
            [61, 'الصَّف',     'As-Saf',         'Barisan',            14,  28, 'Madaniyah'],
            [62, 'الجُمُعَة',  'Al-Jumu\'ah',    'Hari Jum\'at',       11,  28, 'Madaniyah'],
            [63, 'المُنَافِقُون','Al-Munafiqun',   'Orang Munafik',      11,  28, 'Madaniyah'],
            [64, 'التَّغَابُن', 'At-Tagabun',     'Hari Ditampakkan',   18,  28, 'Madaniyah'],
            [65, 'الطَّلَاق',  'At-Talaq',       'Talak',              12,  28, 'Madaniyah'],
            [66, 'التَّحريم',  'At-Tahrim',      'Pengharaman',        12,  28, 'Madaniyah'],
            [67, 'المُلك',     'Al-Mulk',        'Kerajaan',           30,  29, 'Makkiyah'],
            [68, 'القَلَم',    'Al-Qalam',       'Pena',               52,  29, 'Makkiyah'],
            [69, 'الحَاقَّة',  'Al-Haqqah',      'Hari Kiamat',        52,  29, 'Makkiyah'],
            [70, 'المَعَارِج',  'Al-Ma\'arij',    'Tempat Naik',        44,  29, 'Makkiyah'],
            [71, 'نُوح',       'Nuh',            'Nabi Nuh',           28,  29, 'Makkiyah'],
            [72, 'الجِن',      'Al-Jinn',        'Jin',                28,  29, 'Makkiyah'],
            [73, 'المُزَّمِّل', 'Al-Muzzammil',   'Orang Berselimut',   20,  29, 'Makkiyah'],
            [74, 'المُدَّثِّر', 'Al-Muddassir',   'Orang Berkemul',     56,  29, 'Makkiyah'],
            [75, 'القِيَامَة',  'Al-Qiyamah',     'Hari Kiamat',        40,  29, 'Makkiyah'],
            [76, 'الإِنسَان',  'Al-Insan',       'Manusia',            31,  29, 'Madaniyah'],
            [77, 'المُرسَلَات', 'Al-Mursalat',    'Yang Diutus',        50,  29, 'Makkiyah'],
            [78, 'النَّبَأ',   'An-Naba\'',      'Berita Besar',       40,  30, 'Makkiyah'],
            [79, 'النَّازِعَات','An-Nazi\'at',     'Yang Mencabut',      46,  30, 'Makkiyah'],
            [80, 'عَبَس',      '\'Abasa',        'Ia Bermuka Masam',   42,  30, 'Makkiyah'],
            [81, 'التَّكوِير', 'At-Takwir',      'Menggulung',         29,  30, 'Makkiyah'],
            [82, 'الانفِطَار',  'Al-Infitar',     'Terbelah',           19,  30, 'Makkiyah'],
            [83, 'المُطَفِّفِين','Al-Mutaffifin',  'Orang yang Curang',  36,  30, 'Makkiyah'],
            [84, 'الانشِقَاق',  'Al-Insyiqaq',    'Terbelah',           25,  30, 'Makkiyah'],
            [85, 'البُرُوج',   'Al-Buruj',       'Gugusan Bintang',    22,  30, 'Makkiyah'],
            [86, 'الطَّارِق',  'At-Tariq',       'Bintang Pemukul',    17,  30, 'Makkiyah'],
            [87, 'الأَعلَى',   'Al-A\'la',       'Yang Maha Tinggi',   19,  30, 'Makkiyah'],
            [88, 'الغَاشِيَة', 'Al-Gasyiyah',    'Hari Pembalasan',    26,  30, 'Makkiyah'],
            [89, 'الفَجر',     'Al-Fajr',        'Fajar',              30,  30, 'Makkiyah'],
            [90, 'البَلَد',    'Al-Balad',       'Negeri',             20,  30, 'Makkiyah'],
            [91, 'الشَّمس',    'Asy-Syams',      'Matahari',           15,  30, 'Makkiyah'],
            [92, 'اللَّيل',    'Al-Lail',        'Malam',              21,  30, 'Makkiyah'],
            [93, 'الضُّحَى',   'Ad-Duha',        'Waktu Duha',         11,  30, 'Makkiyah'],
            [94, 'الشَّرح',    'Asy-Syarh',      'Melapangkan',        8,   30, 'Makkiyah'],
            [95, 'التِّين',    'At-Tin',         'Pohon Tin',          8,   30, 'Makkiyah'],
            [96, 'العَلَق',    'Al-\'Alaq',      'Segumpal Darah',     19,  30, 'Makkiyah'],
            [97, 'القَدر',     'Al-Qadr',        'Malam Kemuliaan',    5,   30, 'Makkiyah'],
            [98, 'البَيِّنَة',  'Al-Bayyinah',    'Bukti Nyata',        8,   30, 'Madaniyah'],
            [99, 'الزَّلزَلَة', 'Az-Zalzalah',    'Kegoncangan',        8,   30, 'Madaniyah'],
            [100,'العَادِيَات', 'Al-\'Adiyat',    'Yang Berlari Kencang',11, 30, 'Makkiyah'],
            [101,'القَارِعَة',  'Al-Qari\'ah',    'Hari Kiamat',        11,  30, 'Makkiyah'],
            [102,'التَّكَاثُر', 'At-Takasur',     'Bermegah-megahan',   8,   30, 'Makkiyah'],
            [103,'العَصر',     'Al-\'Asr',       'Masa',               3,   30, 'Makkiyah'],
            [104,'الهُمَزَة',   'Al-Humazah',     'Pengumpat',          9,   30, 'Makkiyah'],
            [105,'الفِيل',     'Al-Fil',         'Gajah',              5,   30, 'Makkiyah'],
            [106,'قُرَيش',     'Quraisy',        'Suku Quraisy',       4,   30, 'Makkiyah'],
            [107,'المَاعُون',  'Al-Ma\'un',      'Barang Berguna',     7,   30, 'Makkiyah'],
            [108,'الكَوثَر',   'Al-Kausar',      'Nikmat yang Banyak', 3,   30, 'Makkiyah'],
            [109,'الكَافِرُون', 'Al-Kafirun',     'Orang Kafir',        6,   30, 'Makkiyah'],
            [110,'النَّصر',    'An-Nasr',        'Pertolongan',        3,   30, 'Madaniyah'],
            [111,'المَسَد',    'Al-Masad',       'Sabut',              5,   30, 'Makkiyah'],
            [112,'الإِخلَاص',  'Al-Ikhlas',      'Keikhlasan',         4,   30, 'Makkiyah'],
            [113,'الفَلَق',    'Al-Falaq',       'Waktu Subuh',        5,   30, 'Makkiyah'],
            [114,'النَّاس',    'An-Nas',         'Manusia',            6,   30, 'Makkiyah'],
        ];

        $rows = [];
        foreach ($surahs as $s) {
            $rows[] = [
                'number'      => $s[0],
                'name_arabic' => $s[1],
                'name_latin'  => $s[2],
                'name_id'     => $s[3],
                'total_ayat'  => $s[4],
                'juz_start'   => $s[5],
                'revelation'  => $s[6],
            ];
        }

        $this->db->table('quran_surahs')->insertBatch($rows);
    }

    public function down()
    {
        $this->db->table('quran_surahs')->truncate();
    }
}
