<?php

namespace Modules\MedWard\Entities;

use Illuminate\Database\Eloquent\Model;

/**
 * An inpatient ward (SIFA P6-T1). Optionally linked to a MedOrganization
 * clc_department (dept_id) and an ERP business location — link-only, we never
 * write those tables.
 */
class MedwardWard extends Model
{
    protected $table = 'medward_wards';

    protected $guarded = ['id'];

    protected $casts = [
        'total_beds' => 'integer',
        'is_active'  => 'boolean',
    ];

    public const WARD_TYPES = [
        'general', 'icu', 'nicu', 'picu', 'maternity',
        'surgical', 'medical', 'isolation', 'other',
    ];

    public function beds()
    {
        return $this->hasMany(MedwardBed::class, 'ward_id');
    }

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

    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    /** ICU-family wards use the ICU flow-sheet / dashboard surfaces. */
    public function isIcuType(): bool
    {
        return in_array($this->ward_type, ['icu', 'nicu', 'picu'], true);
    }
}
