<?php
/**
 * Pre-Authorization Form Configuration
 * Maps insurance provider codes to their specific form templates
 */

$PREAUTH_FORM_CONFIG = [
    'CIC' => [
        'template' => 'form_cic.php',
        'name' => 'CIC General Insurance',
        'description' => 'CIC-specific pre-authorization form with declaration, accident claims, and radiology sections'
    ],
    'AAR' => [
        'template' => 'form_aar.php',
        'name' => 'AAR Insurance',
        'description' => 'AAR Insurance specific pre-authorization form'
    ],
    'JUB' => [
        'template' => 'form_jubilee.php',
        'name' => 'Jubilee Health Insurance',
        'description' => 'Jubilee-specific form with scheme details, chronic illness, and maternity sections'
    ],
    'JUBILEE' => [
        'template' => 'form_jubilee.php',
        'name' => 'Jubilee Health Insurance',
        'description' => 'Jubilee-specific form with scheme details, chronic illness, and maternity sections'
    ],
    'APA' => [
        'template' => 'form_apa.php',
        'name' => 'APA Insurance',
        'description' => 'APA-specific form with NHIF membership, caesarian, and clinical summary sections'
    ],
    'GA' => [
        'template' => 'form_ga.php',
        'name' => 'GA Insurance',
        'description' => 'GA Insurance specific pre-authorization form'
    ],
    'MUA' => [
        'template' => 'form_mua.php',
        'name' => 'MUA Insurance',
        'description' => 'MUA Insurance specific pre-authorization form'
    ],
    'MAD' => [
        'template' => 'form_mad.php',
        'name' => 'Madison Insurance',
        'description' => 'Madison Insurance specific pre-authorization form'
    ],
    'MN' => [
        'template' => 'form_mn.php',
        'name' => 'Minet Kenya',
        'description' => 'Minet Kenya specific pre-authorization form'
    ],
    'FA' => [
        'template' => 'form_fa.php',
        'name' => 'First Assurance',
        'description' => 'First Assurance specific pre-authorization form'
    ],
    'OM' => [
        'template' => 'form_om.php',
        'name' => 'Old Mutual',
        'description' => 'Old Mutual specific pre-authorization form'
    ],
    'PAC' => [
        'template' => 'form_pac.php',
        'name' => 'Pacis Insurance',
        'description' => 'Pacis Insurance specific pre-authorization form'
    ],
    'STA' => [
        'template' => 'form_sta.php',
        'name' => 'Star Discover',
        'description' => 'Star Discover specific pre-authorization form'
    ],
    'BRI' => [
        'template' => 'form_bri.php',
        'name' => 'Britam',
        'description' => 'Britam specific pre-authorization form'
    ],
    'FID' => [
        'template' => 'form_fid.php',
        'name' => 'Fidelity Insurance',
        'description' => 'Fidelity Insurance specific pre-authorization form'
    ],
    'CIG' => [
        'template' => 'form_cig.php',
        'name' => 'Cigna',
        'description' => 'Cigna specific pre-authorization form'
    ],
    'LIA' => [
        'template' => 'form_lia.php',
        'name' => 'Liaison Group',
        'description' => 'Liaison Group specific pre-authorization form'
    ],
    'HER' => [
        'template' => 'form_her.php',
        'name' => 'Heritage Insurance',
        'description' => 'Heritage Insurance specific pre-authorization form'
    ],
    'KPLC' => [
        'template' => 'form_kplc.php',
        'name' => 'KPLC Medical Scheme',
        'description' => 'KPLC Medical Scheme specific pre-authorization form'
    ],
    'KGN' => [
        'template' => 'form_kgn.php',
        'name' => 'KenGen Medical Scheme',
        'description' => 'KenGen Medical Scheme specific pre-authorization form'
    ],
    'GDC' => [
        'template' => 'form_gdc.php',
        'name' => 'GDC Geothermal',
        'description' => 'GDC Geothermal specific pre-authorization form'
    ],
    'SED' => [
        'template' => 'form_sed.php',
        'name' => 'Sedgwick',
        'description' => 'Sedgwick specific pre-authorization form'
    ],
    'EAF' => [
        'template' => 'form_eaf.php',
        'name' => 'Eagle Africa',
        'description' => 'Eagle Africa specific pre-authorization form'
    ],
    'KCB' => [
        'template' => 'form_kcb.php',
        'name' => 'KCB Medical Scheme',
        'description' => 'KCB Medical Scheme specific pre-authorization form'
    ],
    'COOP' => [
        'template' => 'form_coop.php',
        'name' => 'Co-operative Bank Scheme',
        'description' => 'Co-operative Bank Scheme specific pre-authorization form'
    ],
    'POST' => [
        'template' => 'form_post.php',
        'name' => 'Postbank Medical Scheme',
        'description' => 'Postbank Medical Scheme specific pre-authorization form'
    ]
];

/**
 * Get form template path for a provider code
 *
 * @param string $provider_code The insurance provider code
 * @return array Form configuration with template path and metadata
 */
function getFormConfig($provider_code)
{
    global $PREAUTH_FORM_CONFIG;

    $provider_code = strtoupper(trim($provider_code));

    if (isset($PREAUTH_FORM_CONFIG[$provider_code])) {
        return $PREAUTH_FORM_CONFIG[$provider_code];
    }

    // Return default form config
    return [
        'template' => 'form_default.php',
        'name' => 'Standard Pre-Authorization',
        'description' => 'Standard pre-authorization form for general use'
    ];
}

/**
 * Check if a provider has a custom form
 *
 * @param string $provider_code The insurance provider code
 * @return bool True if provider has custom form
 */
function hasCustomForm($provider_code)
{
    global $PREAUTH_FORM_CONFIG;
    return isset($PREAUTH_FORM_CONFIG[strtoupper(trim($provider_code))]);
}

/**
 * Get all available form configurations
 *
 * @return array All form configurations
 */
function getAllFormConfigs()
{
    global $PREAUTH_FORM_CONFIG;
    return $PREAUTH_FORM_CONFIG;
}
