<?php
declare(strict_types=1);

function crm_master_definitions(): array
{
    return [
        'status' => [
            'title' => 'Add Status',
            'singular' => 'Status',
            'table' => 'jos_crm_mleadstatus',
            'name_column' => 'name',
            'name_label' => 'Status Name',
            'order_column' => 'orderid',
            'icon' => 'fa-signal',
            'description' => 'Lead pipeline status configuration',
            'references' => [
                ['table' => 'jos_crm_leadentry', 'column' => 'leadstatus', 'label' => 'leads'],
                ['table' => 'jos_crm_lead_followup_grid', 'column' => 'status', 'label' => 'follow-ups'],
            ],
        ],
        'lead-source' => [
            'title' => 'Add Lead Source',
            'singular' => 'Lead Source',
            'table' => 'jos_crm_mleadsource',
            'name_column' => 'leadsource',
            'name_label' => 'Lead Source',
            'order_column' => 'ordering',
            'state_column' => 'state',
            'icon' => 'fa-bullhorn',
            'description' => 'Lead source configuration',
            'references' => [
                ['table' => 'jos_crm_leadentry', 'column' => 'leadsource', 'label' => 'leads'],
            ],
        ],
        'nature' => [
            'title' => 'Add Nature',
            'singular' => 'Nature',
            'table' => 'jos_crm_mleadtypes',
            'name_column' => 'name',
            'name_label' => 'Nature Name',
            'icon' => 'fa-compass',
            'description' => 'Lead nature configuration',
            'references' => [
                ['table' => 'jos_crm_leadentry', 'column' => 'leadtype', 'label' => 'leads'],
                ['table' => 'jos_crm_lead_followup_grid', 'column' => 'leadtype', 'label' => 'follow-ups'],
            ],
        ],
        'segment' => [
            'title' => 'Add Segment',
            'singular' => 'Segment',
            'table' => 'jos_crm_segmentmaster',
            'name_column' => 'segment',
            'name_label' => 'Segment',
            'icon' => 'fa-layer-group',
            'description' => 'Customer segment configuration',
            'references' => [
                ['table' => 'jos_crm_mcustomers', 'column' => 'segment', 'label' => 'customers'],
            ],
        ],
        'lead-category' => [
            'title' => 'Add Lead Category',
            'singular' => 'Lead Category',
            'table' => 'jos_crm_leadcategory',
            'name_column' => 'lcategory',
            'name_label' => 'Lead Category',
            'icon' => 'fa-tags',
            'description' => 'Lead category configuration',
            'references' => [
                ['table' => 'jos_crm_leadentry', 'column' => 'lcategory', 'label' => 'leads'],
            ],
        ],
    ];
}

function crm_master_definition(string $key): array
{
    $definitions = crm_master_definitions();
    if (!isset($definitions[$key])) {
        throw new RuntimeException('Unknown CRM master.');
    }
    return $definitions[$key];
}
