<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddLogoColumnsToSchoolSettings extends Migration
{
    public function up()
    {
        // Cek apakah kolom logo_kemenag sudah ada
        if (!$this->db->fieldExists('logo_kemenag', 'school_settings')) {
            $this->forge->addColumn('school_settings', [
                'logo_kemenag' => [
                    'type'       => 'VARCHAR',
                    'constraint' => 255,
                    'null'       => true,
                    'after'      => 'logo',
                ],
            ]);
        }
        
        // Cek apakah kolom logo_sekolah sudah ada
        if (!$this->db->fieldExists('logo_sekolah', 'school_settings')) {
            $this->forge->addColumn('school_settings', [
                'logo_sekolah' => [
                    'type'       => 'VARCHAR',
                    'constraint' => 255,
                    'null'       => true,
                    'after'      => 'logo_kemenag',
                ],
            ]);
        }
    }

    public function down()
    {
        if ($this->db->fieldExists('logo_kemenag', 'school_settings')) {
            $this->forge->dropColumn('school_settings', 'logo_kemenag');
        }
        if ($this->db->fieldExists('logo_sekolah', 'school_settings')) {
            $this->forge->dropColumn('school_settings', 'logo_sekolah');
        }
    }
}