<?php

namespace App\Models;

use App\Models\Concerns\BelongsToCompany;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class ClinicalDiagnosis extends Model
{
    use HasFactory, SoftDeletes, BelongsToCompany;

    protected $fillable = [
        'company_id', 'clinical_history_id', 'clinical_evolution_id', 'customer_id',
        'cie10_code', 'name', 'type', 'notes', 'created_by',
    ];

    public static array $types = [
        'primary'    => 'Principal',
        'secondary'  => 'Secundario',
        'impression' => 'Impresión diagnóstica',
    ];

    public function clinicalHistory(): BelongsTo
    {
        return $this->belongsTo(ClinicalHistory::class);
    }

    public function evolution(): BelongsTo
    {
        return $this->belongsTo(ClinicalEvolution::class, 'clinical_evolution_id');
    }

    public function customer(): BelongsTo
    {
        return $this->belongsTo(Customer::class);
    }

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

    public function typeLabel(): string
    {
        return self::$types[$this->type] ?? ucfirst($this->type);
    }
}
