<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Prunable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class EbReading extends Model
{
    use Prunable;
    use SoftDeletes;

    protected $fillable = [
        'plant_id',
        'lcd_segment_check',
        'meter_serial_no',
        'eb_date_time',
        'ph_seq_of_volt',
        'ph_assoc_conn_check',
        'instantaneous_ph_volt',
        'instantaneous_curr',
        'instantaneous_freq',
        'instantaneous_kw_with_sign',
        'instantaneous_kva',
        'instantaneous_kv_ar',
        'instantaneous_pf_with_sign',
        'rd_with_elapsed_time_kva',
        'cum_active_import_energy',
        'tod1_active_energy_6_9',
        'tod2_active_energy_18_21',
        'tod3_active_energy_21_22',
        'tod4_active_energy_5_6_9_18',
        'tod5_active_energy_22_5',
        'cum_reac_lag_energy',
        'cum_reac_lead_energy',
        'cum_appar_energy',
        'tod1_appar_energy_6_9',
        'tod2_appar_energy_18_21',
        'tod3_appar_energy_21_22',
        'tod4_appar_energy_5_6_9_18',
        'tod5_appar_energy_22_5',
        'avg_pow_factor',
        'avg_freq_15min_last_ip',
        'net_kv_arh_high',
        'net_kv_arh_low',
        'cum_md_kva',
        'present_md_kva',
        'present_md_kva_date_time',
        'tod1_md_kva_6_9',
        'tod2_md_kva_18_21',
        'tod3_md_kva_21_22',
        'tod4_md_kva_5_6_9_18',
        'tod5_md_kva_22_5',
        'total_pow_off_hours',
        'programming_count',
        'last_occ_res_event_type',
        'last_occ_res_event_date_time',
        'tamper_count',
        'reset_count',
        'last_md_reset_date_time',
        'electrician_sign',
        'updated_by',
    ];

    public function plant(): BelongsTo
    {
        return $this->belongsTo(Plant::class);
    }

    public function prunable(): Builder
    {
        return static::where('created_at', '<=', now()->subMonthsNoOverflow(6));
    }
}
