<?php

namespace App\FieldVisibility;

use Illuminate\Support\Collection;

abstract class AbstractFieldCatalogue implements FieldCatalogue
{
    public function lockableKeys(): array
    {
        return $this->fieldCollection()
            ->where('lockable', true)
            ->pluck('key')
            ->values()
            ->all();
    }

    public function hideableKeys(): array
    {
        return $this->fieldCollection()
            ->where('lockable', false)
            ->pluck('key')
            ->values()
            ->all();
    }

    /**
     * @return Collection<int, array{key: string, label: string, group: string, lockable: bool}>
     */
    private function fieldCollection(): Collection
    {
        return collect($this->fields());
    }

    /**
     * Helper to build a single field definition.
     *
     * @return array{key: string, label: string, group: string, lockable: bool}
     */
    protected function field(string $key, string $label, string $group, bool $lockable = false): array
    {
        return [
            'key' => $key,
            'label' => $label,
            'group' => $group,
            'lockable' => $lockable,
        ];
    }
}
