<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class HealthTreatmentUpdate extends Model
{
    protected $guarded = ['id', 'created_at', 'updated_at'];

    protected $casts = [
        'report_at' => 'datetime',
        'attachments' => 'array',
        'documents' => 'array',
        'total_cost' => 'decimal:0',
        'progress_percent' => 'integer',
    ];

    public function treatment(): BelongsTo
    {
        return $this->belongsTo(HealthTreatment::class, 'health_treatment_id');
    }

    public function consumables(): HasMany
    {
        return $this->hasMany(HealthTreatmentConsumable::class)->orderBy('sort_order');
    }

    public function invoiceItems(): HasMany
    {
        return $this->hasMany(HealthTreatmentInvoiceItem::class)->orderBy('sort_order');
    }

    public function createdBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }
}
