<?php

declare(strict_types=1);

namespace CliqThemes\StoreLocator\Models;

defined('ABSPATH') || exit;

use CliqThemes\ORM\Model;
use CliqThemes\ORM\Relations\BelongsToMany;

/**
 * An admin-defined custom field for stores. May be any registered field type
 * (including `repeater` for repeatable groups) and can be scoped to one or more
 * categories via the custom_field_category pivot.
 */
final class CustomField extends Model
{
    protected string $table = 'cliq_sl_custom_fields';

    protected string $primaryKey = 'id';

    protected array $fillable = [
        'id',
        'field_key',
        'label',
        'type',
        'entity',
        'section',
        'config',
        'is_repeatable',
        'ordering',
        'is_active',
        'created_at',
        'updated_at',
    ];

    public function categories(): BelongsToMany
    {
        return $this->belongsToMany(Category::class, 'cliq_sl_custom_field_category', 'field_id', 'category_id');
    }
}
