<?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 ClinicalNote extends Model
{
    use HasFactory, SoftDeletes, BelongsToCompany;

    protected $fillable = [
        'company_id', 'clinical_history_id', 'booking_id', 'employee_id',
        'created_by', 'title', 'content', 'tags', 'is_private',
    ];

    protected function casts(): array
    {
        return [
            'content'    => 'encrypted',
            'tags'       => 'array',
            'is_private' => 'boolean',
        ];
    }

    public function history(): BelongsTo
    {
        return $this->belongsTo(ClinicalHistory::class, 'clinical_history_id');
    }

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

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

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