<?php
declare(strict_types=1);

function crm_region_definitions(): array
{
    return [
        'state' => [
            'title' => 'Add State',
            'singular' => 'State',
            'table' => 'jos_crm_mstates',
            'icon' => 'fa-map',
            'description' => 'State configuration',
            'references' => [
                ['table' => 'jos_crm_district', 'column' => 'stateid', 'label' => 'districts'],
                ['table' => 'jos_crm_mcitys', 'column' => 'stateid', 'label' => 'talukas'],
                ['table' => 'jos_crm_locality', 'column' => 'stateid', 'label' => 'localities'],
                ['table' => 'jos_crm_mcustomers', 'column' => 'stateid', 'label' => 'customers'],
            ],
        ],
        'district' => [
            'title' => 'Add District',
            'singular' => 'District',
            'table' => 'jos_crm_district',
            'icon' => 'fa-map-location-dot',
            'description' => 'District configuration',
            'references' => [
                ['table' => 'jos_crm_mcitys', 'column' => 'districtid', 'label' => 'talukas'],
                ['table' => 'jos_crm_locality', 'column' => 'districtid', 'label' => 'localities'],
                ['table' => 'jos_crm_mcustomers', 'column' => 'districtid', 'label' => 'customers'],
            ],
        ],
        'taluka' => [
            'title' => 'Add Taluka',
            'singular' => 'Taluka',
            'table' => 'jos_crm_mcitys',
            'icon' => 'fa-city',
            'description' => 'Taluka configuration',
            'references' => [
                ['table' => 'jos_crm_locality', 'column' => 'talukaid', 'label' => 'localities'],
                ['table' => 'jos_crm_mcustomers', 'column' => 'talukaid', 'label' => 'customers'],
            ],
        ],
        'locality' => [
            'title' => 'Add Locality',
            'singular' => 'Locality',
            'table' => 'jos_crm_locality',
            'icon' => 'fa-location-dot',
            'description' => 'Locality configuration',
            'references' => [
                ['table' => 'jos_crm_mcustomers', 'column' => 'localityid', 'label' => 'customers'],
            ],
        ],
    ];
}

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