<?php

namespace App\Models;

use App\Models\Concerns\BelongsToOwner;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class MarAdministration extends Model
{
    use BelongsToOwner;

    public const STATUS_GIVEN = 'given';

    public const STATUS_HELD = 'held';

    public const STATUS_REFUSED = 'refused';

    public const STATUS_MISSED = 'missed';

    protected $table = 'care_mar_administrations';

    protected $fillable = [
        'owner_ref',
        'organization_id',
        'mar_order_id',
        'visit_id',
        'patient_id',
        'care_unit_id',
        'scheduled_for',
        'recorded_at',
        'status',
        'dose_given',
        'route',
        'administered_by',
        'witness_by',
        'reason',
        'notes',
    ];

    protected function casts(): array
    {
        return [
            'scheduled_for' => 'datetime',
            'recorded_at' => 'datetime',
        ];
    }

    public function order(): BelongsTo
    {
        return $this->belongsTo(MarOrder::class, 'mar_order_id');
    }

    public function visit(): BelongsTo
    {
        return $this->belongsTo(Visit::class, 'visit_id');
    }

    public function patient(): BelongsTo
    {
        return $this->belongsTo(Patient::class, 'patient_id');
    }

    public function careUnit(): BelongsTo
    {
        return $this->belongsTo(CareUnit::class, 'care_unit_id');
    }
}
