<?php

namespace App\Models;

use App\Enums\ToothState;
use App\Models\Concerns\BelongsToTenant;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ToothRecord extends Model
{
    use BelongsToTenant, HasFactory;

    protected $fillable = [
        'tenant_id', 'patient_id', 'tooth', 'surfaces', 'condition',
        'state', 'note', 'treatment_plan_item_id', 'recorded_by', 'recorded_at',
    ];

    protected function casts(): array
    {
        return [
            'surfaces' => 'array',
            'state' => ToothState::class,
            'recorded_at' => 'datetime',
        ];
    }

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

    public function planItem(): BelongsTo
    {
        return $this->belongsTo(TreatmentPlanItem::class, 'treatment_plan_item_id');
    }

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

    public function conditionColor(): string
    {
        return config('dental.conditions.'.$this->condition.'.color', '#64748B');
    }

    public function conditionLabel(): string
    {
        return __(config('dental.conditions.'.$this->condition.'.label', ucfirst($this->condition)));
    }
}
