<?php

namespace Modules\MedPortal\Entities;

use Illuminate\Database\Eloquent\Model;

/**
 * A per-patient per-record-type release override (SIFA Phase 8). Absence of a
 * row means "use the config default" (RecordAccessService). Presence overrides:
 * released=true reveals early, released=false hides a normally-visible type.
 */
class MportalRecordRelease extends Model
{
    protected $table = 'mportal_record_releases';

    protected $guarded = ['id'];

    protected $casts = [
        'released'    => 'boolean',
        'released_at' => 'datetime',
    ];

    public const RECORD_TYPES = ['clinical_note', 'lab_result', 'imaging_report', 'prescription', 'vitals', 'full'];

    public function scopeForBusiness($query, $businessId)
    {
        return $query->where('business_id', $businessId);
    }

    public function scopeForPatient($query, $patientId)
    {
        return $query->where('patient_id', $patientId);
    }
}
