<?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,
            ],
            'nama_sekolah' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'alamat_sekolah' => [
                '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,
            ],
            'favicon' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],
            'kop_surat' => [
                'type' => 'VARCHAR',
                'constraint' => 255,
            ],

            'updated_at' => [
                'type' => 'TIMESTAMP',
                'null' => true,
            ],

        ]);
        $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',
            'updated_at' => date('Y-m-d H:i:s')
        ];

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

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