<?php

namespace App\Models;

use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CustomField extends Model
{
    use BelongsToTenant;

    protected $fillable = [
        'tenant_id', 'entity_type', 'label', 'name', 'type',
        'options', 'is_required', 'is_active', 'show_in_list',
        'sort_order', 'default_value', 'placeholder', 'help_text',
    ];

    protected $casts = [
        'options'      => 'array',
        'is_required'  => 'boolean',
        'is_active'    => 'boolean',
        'show_in_list' => 'boolean',
    ];

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

    public function values(): HasMany
    {
        return $this->hasMany(CustomFieldValue::class);
    }
}
