<?php

namespace Modules\Vrc\Entities;

use Illuminate\Database\Eloquent\Model;

class VrcHazard extends Model
{
    protected $table = 'vrc_hazards';

    protected $fillable = [
        'business_id', 'location_id', 'area', 'hazard', 'risk_description',
        'likelihood', 'severity', 'risk_score', 'risk_level', 'controls',
        'residual_level', 'owner_id', 'review_due', 'status',
    ];

    protected $casts = [
        'likelihood' => 'integer',
        'severity'   => 'integer',
        'risk_score' => 'integer',
        'review_due' => 'date',
    ];

    /** Risk score (likelihood × severity) → band. */
    public static function level(int $likelihood, int $severity): array
    {
        $score = max(1, $likelihood) * max(1, $severity);
        $band = $score >= 15 ? 'extreme' : ($score >= 8 ? 'high' : ($score >= 4 ? 'medium' : 'low'));
        return [$score, $band];
    }
}
