<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
         $sql = <<<'SQL'
            CREATE TABLE eb_readings (
                id						BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
                plant_id            	BIGINT NOT NULL,

                lcd_segment_check   	TEXT DEFAULT NULL,
                meter_serial_no     	TEXT DEFAULT NULL,
                eb_date_time        	TIMESTAMP NOT NULL DEFAULT NOW(),
                ph_seq_of_volt				TEXT DEFAULT NULL,
                ph_assoc_conn_check			TEXT DEFAULT NULL,
                instantaneous_ph_volt		TEXT DEFAULT NULL,
                instantaneous_curr			TEXT DEFAULT NULL,
                instantaneous_freq			TEXT DEFAULT NULL,
                instantaneous_kw_with_sign	TEXT DEFAULT NULL,
                instantaneous_kva			TEXT DEFAULT NULL,
                instantaneous_kv_ar			TEXT DEFAULT NULL,
                instantaneous_pf_with_sign	TEXT DEFAULT NULL,
                rd_with_elapsed_time_kva	TEXT DEFAULT NULL,
                cum_active_import_energy	TEXT DEFAULT NULL,
                tod1_active_energy_6_9		TEXT DEFAULT NULL,
                tod2_active_energy_18_21	TEXT DEFAULT NULL,
                tod3_active_energy_21_22	TEXT DEFAULT NULL,
                tod4_active_energy_5_6_9_18	TEXT DEFAULT NULL,
                tod5_active_energy_22_5		TEXT DEFAULT NULL,
                cum_reac_lag_energy			TEXT DEFAULT NULL,
                cum_reac_lead_energy		TEXT DEFAULT NULL,
                cum_appar_energy			TEXT DEFAULT NULL,
                tod1_appar_energy_6_9		TEXT DEFAULT NULL,
                tod2_appar_energy_18_21		TEXT DEFAULT NULL,
                tod3_appar_energy_21_22		TEXT DEFAULT NULL,
                tod4_appar_energy_5_6_9_18	TEXT DEFAULT NULL,
                tod5_appar_energy_22_5		TEXT DEFAULT NULL,
                avg_pow_factor				TEXT DEFAULT NULL,
                avg_freq_15min_last_ip		TEXT DEFAULT NULL,
                net_kv_arh_high				TEXT DEFAULT NULL,
                net_kv_arh_low				TEXT DEFAULT NULL,
                cum_md_kva					TEXT DEFAULT NULL,
                present_md_kva				TEXT DEFAULT NULL,
                present_md_kva_date_time	TIMESTAMP NOT NULL DEFAULT NOW(),
                tod1_md_kva_6_9				TEXT DEFAULT NULL,
                tod2_md_kva_18_21			TEXT DEFAULT NULL,
                tod3_md_kva_21_22			TEXT DEFAULT NULL,
                tod4_md_kva_5_6_9_18		TEXT DEFAULT NULL,
                tod5_md_kva_22_5			TEXT DEFAULT NULL,
                total_pow_off_hours			TEXT DEFAULT NULL,
                programming_count			TEXT DEFAULT NULL,
                last_occ_res_event_type		TEXT DEFAULT NULL,
                last_occ_res_event_date_time	TIMESTAMP NOT NULL DEFAULT NOW(),
                tamper_count				TEXT DEFAULT NULL,
                reset_count					TEXT DEFAULT NULL,
                last_md_reset_date_time		TIMESTAMP NOT NULL DEFAULT NOW(),
                electrician_sign			TEXT DEFAULT NULL,

                created_at			TIMESTAMP NOT NULL DEFAULT NOW(),
                updated_at			TIMESTAMP NOT NULL DEFAULT NOW(),
                deleted_at			TIMESTAMP,
                updated_by			TEXT NULL,

                FOREIGN KEY (plant_id)      REFERENCES  plants (id)

            );
        SQL;

        DB::statement($sql);
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('eb_readings');
    }
};
