<?php

namespace App\Models;

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

class InvestigationResult extends Model
{
    use BelongsToOwner;

    public const STATUS_DRAFT = 'draft';

    public const STATUS_APPROVED = 'approved';

    protected $table = 'care_investigation_results';

    protected $fillable = [
        'owner_ref', 'investigation_request_id', 'result_summary', 'interpretation',
        'is_abnormal', 'status', 'entered_by', 'approved_by', 'approved_at',
    ];

    protected function casts(): array
    {
        return [
            'is_abnormal' => 'boolean',
            'approved_at' => 'datetime',
        ];
    }

    public function request(): BelongsTo
    {
        return $this->belongsTo(InvestigationRequest::class, 'investigation_request_id');
    }

    public function values(): HasMany
    {
        return $this->hasMany(InvestigationResultValue::class, 'investigation_result_id');
    }

    public function attachments(): HasMany
    {
        return $this->hasMany(InvestigationAttachment::class, 'investigation_result_id');
    }
}
