<?php
/**
 * Shared role labels/slugs for church staff and system user creation.
 *
 * Used by: /system/users/create, /system/users/edit, /users (list + form), /users/delete.
 */

/**
 * Church staff roles creatable under /users (church admin) and /system/users/create.
 *
 * @return array<string, string> role slug => description label
 */
function nazarethChurchStaffRoleLabels(): array
{
    return [
        'clerk' => 'Clerk (members, households, attendance)',
        'data_collector' => 'Data collection (desktop + mobile + households)',
        'reg_coordinator' => 'Registration progress (read-only dashboard; no data entry)',
        'finance' => 'Finance (finance data + record offerings; view members only)',
        'voting' => 'Voting (manage voting system and elections)',
        'group_manager' => 'Gen. Grps manager (manage assigned generational groups only)',
    ];
}

/** @return list<string> */
function nazarethChurchStaffRoleSlugs(): array
{
    return array_keys(nazarethChurchStaffRoleLabels());
}

/**
 * All roles a system admin may create from /system/users/create (includes system_admin + church admin + staff).
 *
 * @return array<string, string> role slug => label (long description for headings)
 */
function nazarethSystemCreatableRoleLabels(): array
{
    return array_merge(
        [
            'system_admin' => 'System Administrator',
            'admin' => 'Church Administrator (full church app)',
        ],
        nazarethChurchStaffRoleLabels()
    );
}

/** @return list<string> */
function nazarethSystemCreatableRoleSlugs(): array
{
    return array_keys(nazarethSystemCreatableRoleLabels());
}

/** Short label for “Create …” buttons on system users page. */
function nazarethSystemCreateButtonLabel(string $role): string
{
    static $short = [
        'system_admin' => 'System Admin',
        'admin' => 'Church Admin',
        'clerk' => 'Clerk',
        'data_collector' => 'Data collector',
        'reg_coordinator' => 'Registration coordinator',
        'finance' => 'Finance',
        'voting' => 'Voting',
        'group_manager' => 'Gen. grps manager',
    ];

    return $short[$role] ?? ucfirst(str_replace('_', ' ', $role));
}

/**
 * Church roles a system admin may assign when editing an existing user (not system_admin).
 *
 * @return array<string, string> slug => long label (form select)
 */
function nazarethSystemEditableChurchRoleLabels(): array
{
    return array_merge(
        [
            'admin' => 'Church Administrator (full church app)',
        ],
        nazarethChurchStaffRoleLabels()
    );
}

/** @return list<string> */
function nazarethSystemEditableChurchRoleSlugs(): array
{
    return array_keys(nazarethSystemEditableChurchRoleLabels());
}

/**
 * Short label for user lists (Users page, badges). Covers roles visible in the church app + system_admin.
 */
function nazarethUserRoleShortLabel(string $role): string
{
    static $map = [
        'system_admin' => 'System admin',
        'admin' => 'Church administrator',
        'clerk' => 'Clerk',
        'data_collector' => 'Data collector',
        'reg_coordinator' => 'Registration coordinator',
        'finance' => 'Finance',
        'voting' => 'Voting',
        'group_manager' => 'Gen. grps manager',
    ];

    return $map[$role] ?? ucfirst(str_replace('_', ' ', $role));
}
