<?php

namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class ConvertDatesToDatetime extends Migration
{
    public function up()
    {
        // Modify tabel_laporan periode columns to DATETIME
        try {
            $this->forge->modifyColumn('tabel_laporan', [
                'periode_awal' => [
                    'name' => 'periode_awal',
                    'type' => 'DATETIME',
                    'null' => true,
                ],
                'periode_akhir' => [
                    'name' => 'periode_akhir',
                    'type' => 'DATETIME',
                    'null' => true,
                ],
            ]);
        } catch (\Exception $e) {
            // ignore if modification not possible
        }

        // Modify tabel_permintaan_custom estimasi_selesai to DATETIME
        try {
            $this->forge->modifyColumn('tabel_permintaan_custom', [
                'estimasi_selesai' => [
                    'name' => 'estimasi_selesai',
                    'type' => 'DATETIME',
                    'null' => true,
                ],
            ]);
        } catch (\Exception $e) {
            // ignore
        }
    }

    public function down()
    {
        // Revert changes (back to DATE)
        try {
            $this->forge->modifyColumn('tabel_laporan', [
                'periode_awal' => [
                    'name' => 'periode_awal',
                    'type' => 'DATE',
                    'null' => true,
                ],
                'periode_akhir' => [
                    'name' => 'periode_akhir',
                    'type' => 'DATE',
                    'null' => true,
                ],
            ]);
        } catch (\Exception $e) {
        }

        try {
            $this->forge->modifyColumn('tabel_permintaan_custom', [
                'estimasi_selesai' => [
                    'name' => 'estimasi_selesai',
                    'type' => 'DATE',
                    'null' => true,
                ],
            ]);
        } catch (\Exception $e) {
        }
    }
}
