<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class ConvertOrderDatesToDatetime extends Migration
{
    public function up()
    {
        // Convert tanggal_order, tanggal_pengambilan, tanggal_pelunasan to DATETIME
        $fields = [
            'tanggal_order' => ['name' => 'tanggal_order', 'type' => 'DATETIME', 'null' => true],
            'tanggal_pengambilan' => ['name' => 'tanggal_pengambilan', 'type' => 'DATETIME', 'null' => true],
            'tanggal_pelunasan' => ['name' => 'tanggal_pelunasan', 'type' => 'DATETIME', 'null' => true],
        ];

        try {
            $this->forge->modifyColumn('tabel_permintaan_custom', $fields);
        } catch (\Exception $e) {
            // ignore if already modified
        }
    }

    public function down()
    {
        // Revert back to DATE if needed
        $fields = [
            'tanggal_order' => ['name' => 'tanggal_order', 'type' => 'DATE', 'null' => true],
            'tanggal_pengambilan' => ['name' => 'tanggal_pengambilan', 'type' => 'DATE', 'null' => true],
            'tanggal_pelunasan' => ['name' => 'tanggal_pelunasan', 'type' => 'DATE', 'null' => true],
        ];

        try {
            $this->forge->modifyColumn('tabel_permintaan_custom', $fields);
        } catch (\Exception $e) {
            // ignore
        }
    }
}
