<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;

#[Fillable([
    'flipped_on_at',
    'flipped_off_at',
    'trigger',
    'trigger_detail',
    'active',
])]
class VolatilityRegime extends Model
{
    protected function casts(): array
    {
        return [
            'flipped_on_at' => 'datetime',
            'flipped_off_at' => 'datetime',
            'active' => 'boolean',
        ];
    }

    public static function currentlyActive(): ?self
    {
        return static::query()->where('active', true)->orderByDesc('flipped_on_at')->first();
    }
}
