<?php

namespace Modules\ClinicCore\Entities;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class ClcAppointmentDocument extends Model
{
    protected $table    = 'clc_appointment_documents';
    protected $guarded  = ['id'];

    public function appointment()
    {
        return $this->belongsTo(ClcAppointment::class, 'appointment_id');
    }

    public function uploader()
    {
        return $this->belongsTo(\App\User::class, 'user_id');
    }

    public function getUrlAttribute()
    {
        return Storage::disk('public')->url($this->file_path);
    }

    public function getFileSizeKbAttribute()
    {
        return $this->file_size ? round($this->file_size / 1024, 1) : null;
    }

    public function getTypeLabelAttribute()
    {
        return [
            'lab_report'        => 'Lab Report',
            'xray'              => 'X-Ray',
            'prescription'      => 'Prescription',
            'consent_form'      => 'Consent Form',
            'discharge_summary' => 'Discharge Summary',
            'other'             => 'Other',
        ][$this->document_type] ?? ucfirst($this->document_type);
    }
}
