<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Traits\Auditable;

class PatientCustomField extends Model
{
    use HasFactory;
    use Auditable;
    
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'type',
        'options',
        'placeholder',
        'required',
        'order',
        'active',
        'created_by'
    ];
    
    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'options' => 'array',
        'required' => 'boolean',
        'active' => 'boolean',
        'order' => 'integer'
    ];
    
    /**
     * Get the values for this field.
     */
    public function values(): HasMany
    {
        return $this->hasMany(PatientCustomFieldValue::class, 'field_id');
    }
    
    /**
     * Get the user that created the field.
     */
    public function createdBy(): BelongsTo
    {
        return $this->belongsTo(User::class, 'created_by');
    }
    
    /**
     * Get available field types
     * 
     * @return array
     */
    public static function getAvailableTypes(): array
    {
        return [
            'text' => 'Text',
            'number' => 'Number',
            'email' => 'Email',
            'phone' => 'Phone',
            'date' => 'Date',
            'textarea' => 'Text Area',
            'select' => 'Select Dropdown',
            'checkbox' => 'Checkbox',
            'radio' => 'Radio Buttons'
        ];
    }
}
