<?php

namespace App\Models\Mitigation;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Prunable;

/**
 * Used to track what Creatia last knew about an attack per what is stored in Oculi.
 * This is a mirror of what's stored purely to facilitate timely calculations.
 */
class MitigationAttackState extends Model
{
    use Prunable;

    protected $table = 'mitigation_attack_state';

    protected $fillable = [
        'attack_id',
        'organisation_id',
        'destination',
        'started_at',
        'finished_at',
        'ongoing',
        'ready',
        'report',
        'gbps',
        'mpps',
        'descriptor'
    ];

    protected $casts = [
        'created_at'    => 'datetime',
        'updated_at'    => 'datetime',
        'started_at'    => 'datetime',
        'finished_at'   => 'datetime',
        'ongoing'       => 'boolean',
        'ready'         => 'boolean',
        'report'        => 'boolean',
        'gbps'          => 'float',
        'mpps'          => 'float',
    ];

    public function prunable() {
        return static::where('updated_at', '<=', now()->subDays(90));
    }
}
