<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ProfileField extends Model
{
    use HasFactory;

    protected $fillable = [
        'association_id',
        'group_id',
        'key',
        'label',
        'field_type',
        'options',
        'is_searchable',
        'is_filterable',
        'is_required',
        'is_visible',
        'default_value',
        'order',
    ];

    protected $casts = [
        'options' => 'json',
        'is_searchable' => 'boolean',
        'is_filterable' => 'boolean',
        'is_required' => 'boolean',
        'is_visible' => 'boolean',
        'order' => 'integer',
    ];

    public function association()
    {
        return $this->belongsTo(Association::class);
    }

    public function group()
    {
        return $this->belongsTo(ProfileFieldGroup::class, 'group_id');
    }

    public function settings()
    {
        return $this->hasMany(AssociationProfileFieldSetting::class);
    }

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