<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class AddAiSettingsToSchoolSettings extends Migration
{
    public function up()
    {
        if ($this->db->fieldExists('ai_provider', 'school_settings')) return;
        $this->forge->addColumn('school_settings', [
            'ai_provider' => [
                'type'       => 'VARCHAR',
                'constraint' => 50,
                'default'    => 'gemini',
                'null'       => true,
                'after'      => 'student_rules'
            ],
            'ai_api_key' => [
                'type'       => 'TEXT',
                'null'       => true,
                'after'      => 'ai_provider'
            ]
        ]);
    }

    public function down()
    {
        $this->forge->dropColumn('school_settings', ['ai_provider', 'ai_api_key']);
    }
}
