<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class Settings extends Migration
{
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type' => 'INT',
                'constraint' => 11,
                'unsigned' => true,
            ],
            'appname' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'npsn' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'nss' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'nama_sekolah' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'jenjang' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'website' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'email' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'alamat_sekolah' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'kelurahan' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'kecamatan' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'kabupaten_kota' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'provinsi' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'nama_kepsek' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'nip_kepsek' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'tahunpelajaran' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'logo' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'logo64' => [
                'type' => 'LONGTEXT',
            ],
            'favicon' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'kop_surat' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'key_encrypt' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'updated_at' => [
                'type' => 'TIMESTAMP',

            ],

        ]);
        $this->forge->addKey('id', true);
        $this->forge->createTable('settings');

        // Menambahkan data awal
        $data = [
            'id' => 1,
            'appname' => 'Nama Aplikasi',
            'nama_sekolah' => 'Nama Sekolah',
            'alamat_sekolah' => 'Alamat Sekolah',
            'nama_kepsek' => 'Nama Kepala Sekolah',
            'nip_kepsek' => 'NIP Kepala Sekolah',
            'tahunpelajaran' => 'Tahun Pelajaran',
            'logo' => 'logo.png',
            'favicon' => 'favicon.ico',
            'kop_surat' => 'kop.png',

        ];

        $this->db->table('settings')->insert($data);
    }

    public function down()
    {
        $this->forge->dropTable('settings');
    }
}
