<?php

namespace Modules\MedWard\Entities;

use Illuminate\Database\Eloquent\Model;

/**
 * A physical bed (SIFA P6-T1). status + cleaning_status drive the bed-board
 * colour. current_admission_id is the denormalised occupant, kept in step by
 * AdmissionService.
 */
class MedwardBed extends Model
{
    protected $table = 'medward_beds';

    protected $guarded = ['id'];

    public const BED_TYPES = ['standard', 'electric', 'pediatric', 'incubator', 'isolation', 'other'];

    public const STATUSES = ['available', 'occupied', 'reserved', 'maintenance', 'blocked'];

    public const CLEANING_STATUSES = ['clean', 'dirty', 'cleaning'];

    public function ward()
    {
        return $this->belongsTo(MedwardWard::class, 'ward_id');
    }

    public function currentAdmission()
    {
        return $this->belongsTo(MedwardAdmission::class, 'current_admission_id');
    }

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

    public function scopeAvailable($query)
    {
        return $query->where('status', 'available');
    }

    /** Bootstrap colour for the bed-board card by status. */
    public function statusColor(): string
    {
        return [
            'available'   => 'success',
            'occupied'    => 'danger',
            'reserved'    => 'warning',
            'maintenance' => 'default',
            'blocked'     => 'default',
        ][$this->status] ?? 'default';
    }
}
