<?php

/**
 * ======================================================================
 *       NASTAVENI CEST ESHOPU
 * ======================================================================.
 */
// ## data: cesta k adresari, kam se ukladaji vsechny soubory

$cfg['Path']['data'] = 'data/';
// ## photos: cesta k adresari, kam se ukladaji fotky zbozi
$cfg['Path']['photos'] = $cfg['Path']['data'].'photos/';
// ## producers: cesta k adresari, kam se ukladaji loga vyrobcu
$cfg['Path']['producers'] = $cfg['Path']['data'].'producer/';
// ## db_backup: cesta k adresari, kam se ukladaji zalohy databaze
$cfg['Path']['db_backup'] = $cfg['Path']['data'].'backup/';
// ## photos: cesta k adresari, kde jsou obrazky designu
$cfg['Path']['images'] = 'templates/images/';
// ## photos: cesta k adresari, kde jsou obrazky designu
$cfg['Path']['web_css'] = 'templates/css/';
// ## shared_dirs_http: cesta ke sdilenym souborum zvenku pres HTTP
$cfg['Path']['shared_dirs_http'] = 'https://shared.kupshop.cz/';
// ## shared_dirs: cesta ke sdilenym souborum zevnitr FTP
$cfg['Path']['shared_dirs'] = '../';
// ## shared_version_http: cesta ke sdilenym souborum zvenku pres HTTP
$cfg['Path']['shared_version_http'] = '/engine/';
// ## shared_version_http: cesta ke sdilenym souborum verze zevnitr FTP
$cfg['Path']['shared_version'] = './engine/';
// ## shared_class: cesta ke sdilenym tridam PHP
$cfg['Path']['shared_class'] = $cfg['Path']['shared_version'].'class/';
// ## admin_images: cesta ke sdilenym obrazkum administrace
$cfg['Path']['admin_images'] = $cfg['Path']['shared_version_http'].'admin/images/';
// ## smarty: cesta ke kompilatoru sablon SMARTY
$cfg['Path']['smarty'] = $cfg['Path']['shared_class'].'smarty/';
// ## smarty: cesta k sablonam
$cfg['Path']['smarty_tpl']['templates'] = 'templates/';
$cfg['Path']['web_root'] = '';
if (!isset($cfg['Path']['admin'])) {
    $cfg['Path']['admin'] = 'admin/';
}

// ################################################################
// KONTROLA FORMATU CONFIGU
// ################################################################

if (!isset($cfg['Modules']['order_discount'])) {
    $cfg['Modules']['order_discount'] = [
        'discounts_coupons' => true,
    ];
}

// Order countries

if (empty($cfg['Order']['Countries'])) {
    $cfg['Order']['Countries'] = [
        'CZ' => 'Česká republika',
        'SK' => 'Slovensko',
    ];
}

// Captcha shared keys
$cfg['Modules']['recaptcha']['site_shared'] = '6LfofPkUAAAAAG2prDjCHJz9V3VcHbuxtKhFiTWd';
$cfg['Modules']['recaptcha']['secret_shared'] = '6LfofPkUAAAAAFKoivTbPw5WtA7V8DjSOxvRaPPr';
// Klíče Cloudflare s názvem wpjshop
$cfg['Modules']['recaptcha']['site_cloudflare'] = '0x4AAAAAAADvWii8pCQ2HqyT';
$cfg['Modules']['recaptcha']['secret_cloudflare'] = '0x4AAAAAAADvWnWF2nOVP7fuBmqc1Z70J9A';
$cfg['Modules']['recaptcha']['site_cloudflare_invisible'] = '0x4AAAAAAAEGsqx8gtD2edMg';
$cfg['Modules']['recaptcha']['secret_cloudflare_invisible'] = '0x4AAAAAAAEGso-2a36i9f3dMFRp0K98N3k';

if (!empty($cfg['Modules']['recaptcha']['cloudflare']) && $cfg['Modules']['recaptcha']['cloudflare'] !== true) {
    switch ($cfg['Modules']['recaptcha']['cloudflare']) {
        case 2: // Klíče Cloudflare s názvem wpjshop 2
            $cfg['Modules']['recaptcha']['site_cloudflare'] = '0x4AAAAAAAKHA_3kFNt3MluK';
            $cfg['Modules']['recaptcha']['secret_cloudflare'] = '0x4AAAAAAAKHA0RLvwc5MhuEcbjkizYuhag';
            $cfg['Modules']['recaptcha']['site_cloudflare_invisible'] = '0x4AAAAAAAKHBe2XIpuARsSK';
            $cfg['Modules']['recaptcha']['secret_cloudflare_invisible'] = '0x4AAAAAAAKHBZ72uHyG1CLnXztnTbM4Nxg';
            break;
        case 3: // Klíče Cloudflare s názvem wpjshop 3
            $cfg['Modules']['recaptcha']['site_cloudflare'] = '0x4AAAAAAAOEjF8jk57LdPLo';
            $cfg['Modules']['recaptcha']['secret_cloudflare'] = '0x4AAAAAAAOEjPPH9Ni7djzqDjkQl6vRXUY';
            $cfg['Modules']['recaptcha']['site_cloudflare_invisible'] = '0x4AAAAAAAOEkAcxiqSikawO';
            $cfg['Modules']['recaptcha']['secret_cloudflare_invisible'] = '0x4AAAAAAAOEkL0vW40-x3BISVF7LDaBz7I';
            break;
        case 4: // Klíče Cloudflare s názvem wpjshop 4
            $cfg['Modules']['recaptcha']['site_cloudflare'] = '0x4AAAAAAAQjiZgIQANJ2o_Y';
            $cfg['Modules']['recaptcha']['secret_cloudflare'] = '0x4AAAAAAAQjiQOkCYIfNM7iLkgeKsqh1QA';
            $cfg['Modules']['recaptcha']['site_cloudflare_invisible'] = '0x4AAAAAAAQjircUH8FfQdfn';
            $cfg['Modules']['recaptcha']['secret_cloudflare_invisible'] = '0x4AAAAAAAQjin-X8EW7s3CmHWLhbQymMLA';
            break;
        case 5: // Klíče Cloudflare s názvem wpjshop 5
            $cfg['Modules']['recaptcha']['site_cloudflare'] = '0x4AAAAAAAXLVA5D9pevta-E';
            $cfg['Modules']['recaptcha']['secret_cloudflare'] = '0x4AAAAAAAXLVFS5dNZtwyJHGO16weN8jIA';
            $cfg['Modules']['recaptcha']['site_cloudflare_invisible'] = '0x4AAAAAAAXLVnW96fC2LFiw';
            $cfg['Modules']['recaptcha']['secret_cloudflare_invisible'] = '0x4AAAAAAAXLVtEOp0qvr1QoDDxNagE7lgk';
            break;
        case 6: // Klíče Cloudflare s názvem wpjshop 6
            $cfg['Modules']['recaptcha']['site_cloudflare'] = '0x4AAAAAAAxsqU5xYh2GRQCR';
            $cfg['Modules']['recaptcha']['secret_cloudflare'] = '0x4AAAAAAAxsqVjRGj-V-ZtGNRwXBKsyEQo';
            $cfg['Modules']['recaptcha']['site_cloudflare_invisible'] = '0x4AAAAAAAxssIptvzIjBYGH';
            $cfg['Modules']['recaptcha']['secret_cloudflare_invisible'] = '0x4AAAAAAAxssNmopVcbjYuTcBkBI032jV8';
            break;
        case 7: // Klíče Cloudflare s názvem wpjshop 7
            $cfg['Modules']['recaptcha']['site_cloudflare'] = '0x4AAAAAABBkorhLJZvYX-eQ';
            $cfg['Modules']['recaptcha']['secret_cloudflare'] = '0x4AAAAAABBkojH5rz2Yu_o8VNc3TZeHJ_4';
            $cfg['Modules']['recaptcha']['site_cloudflare_invisible'] = '0x4AAAAAABBkpPomgW5qPNGG';
            $cfg['Modules']['recaptcha']['secret_cloudflare_invisible'] = '0x4AAAAAABBkpK5vHvId698KKDBwJBEFzfE';
            break;
        case 8: // Klíče Cloudflare s názvem wpjshop 8
            $cfg['Modules']['recaptcha']['site_cloudflare'] = '0x4AAAAAABGZgq80sV3hU7m6';
            $cfg['Modules']['recaptcha']['secret_cloudflare'] = '0x4AAAAAABGZguz73Vb-o-YFaqYqmGugl70';
            $cfg['Modules']['recaptcha']['site_cloudflare_invisible'] = '0x4AAAAAABGZlx00-GW5be_M';
            $cfg['Modules']['recaptcha']['secret_cloudflare_invisible'] = '0x4AAAAAABGZl4Td33EoR6uSLKFkDrbc1s8';
            break;
    }

    if (isset($_SERVER['HTTP_HOST']) && !empty($cfg['Modules']['recaptcha']['domains'][$_SERVER['HTTP_HOST']])) {
        $cfg['Modules']['recaptcha'] = array_merge($cfg['Modules']['recaptcha'], $cfg['Modules']['recaptcha']['domains'][$_SERVER['HTTP_HOST']]);
    }
}

// Product flags
if (!isset($cfg['Products']['Flags'])) {
    $cfg['Products']['Flags'] = [
        'N' => ['plural' => 'Novinky', 'singular' => 'Novinka', 'url' => 'novinky', 'short' => 'N', 'order' => -4],
        'D' => ['plural' => 'Akce', 'singular' => 'Akce', 'url' => 'akce', 'short' => 'A', 'order' => -6],
        'S' => ['plural' => 'Nejprodávanější zboží', 'singular' => 'Nejprodávanější zboží', 'url' => 'nejprodavanejsi', 'short' => 'P'],
        'L' => ['plural' => 'Na úvodu', 'singular' => 'Na úvodu', 'url' => 'uvod', 'short' => 'Ú'],
        'A' => ['plural' => 'Výprodej', 'singular' => 'Výprodej', 'url' => 'vyprodej', 'short' => 'V', 'order' => -6],
        'M' => ['plural' => 'Newsletter', 'singular' => 'Newsletter', 'url' => 'newsletter', 'short' => 'M'],
        'Z' => ['plural' => 'Doprava zdarma', 'singular' => 'Doprava zdarma', 'url' => 'doprava-zdarma', 'short' => 'D'],
    ];
}

if ($cfg['Products']['Flags'] !== []) {
    $cfg['Products']['UrlFlags'] = join('|', array_merge(array_keys($cfg['Products']['Flags']), ['F', 'W']));
}

// Relative address of eshop in web root
if (!isset($cfg['Addr']['rel'])) {
    $cfg['Addr']['rel'] = '/';
}

// Cache prefix
if (!isset($cfg['Cache']['prefix'])) {
    $cfg['Cache']['prefix'] = $cfg['Addr']['print'];
}

$cfg['Cache']['symfonyMemcached'] = 'memcached://kocour.wpj.cz:11211?prefix_key='.$cfg['Cache']['prefix'];

// Load custom classes from shop folder
if (!isset($cfg['autoload_web_root'])) {
    $cfg['autoload_web_root'] = true;
}

// Full path to shared templates
if (!isset($cfg['Path']['shared_templates_http'])) {
    $cfg['Path']['shared_templates_http'] = $cfg['Path']['shared_version_http']."web/templates/{$cfg['Path']['smarty_tpl']['theme']}/";
}

// Wpj Toolbar
if (!isset($cfg['Menu']['wpj_toolbar'])) {
    $cfg['Menu']['wpj_toolbar'] = [
        'show' => true,
        'admin_url' => '/admin/',
    ];
}

/*
 * ======================================================================
 *       NASTAVENI OBJEDNAVEK
 * ======================================================================
 * Status: nastaveni stavu objednavek

 */

if (empty($cfg['Order']['Status']['payed'])) {
    $cfg['Order']['Status']['payed'][0] = 'čeká na zaplacení';
    $cfg['Order']['Status']['payed'][1] = 'zaplaceno';
    $cfg['Order']['Status']['payed'][2] = 'nedoplatek';
    $cfg['Order']['Status']['payed'][3] = 'přeplatek';
}

if (empty($cfg['Order']['Status']['storno'])) {
    $cfg['Order']['Status']['storno'][0] = 'nestornována';
    $cfg['Order']['Status']['storno'][1] = 'stornována';
}

if (!isset($cfg['Order']['Flags']['NE'])) {
    $cfg['Order']['Flags']['NE'] = ['name' => 'Nedoručitelný e-mail'];
}

if (!isset($cfg['Order']['Flags']['R'])) {
    $cfg['Order']['Flags']['R'] = ['name' => 'Nedořešená poznámka'];
}

if (!empty($cfg['Modules']['dropship'])) {
    if (!isset($cfg['Order']['Flags']['DSE'])) {
        $cfg['Order']['Flags']['DSE'] = ['name' => 'Expando objednávka'];
    }

    if (!isset($cfg['Order']['Flags']['DSM'])) {
        $cfg['Order']['Flags']['DSM'] = ['name' => 'MALL objednávka'];
    }

    if (!isset($cfg['Order']['Flags']['DSC'])) {
        $cfg['Order']['Flags']['DSC'] = ['name' => 'Channable objednávka'];
    }
}

if (!empty($cfg['Modules']['pos']) || !empty($cfg['Modules']['new_pos'])) {
    $cfg['Order']['Flags']['POS'] = ['name' => 'Nákup přes pokladnu'];
    $cfg['Order']['Flags']['POR'] = ['name' => 'Připraveno na pokladně'];
}

if (!empty($cfg['Modules']['returns'])) {
    $cfg['Order']['Status']['global'][100] = 'čeká na vrácení';
}

if ($cfg['Products']['Flags'] !== [] && !empty($cfg['Modules']['global_discounts'])) {
    $cfg['Products']['Flags']['FS'] = ['plural' => 'Fixní sleva', 'singular' => 'Fixní sleva', 'short' => 'FS'];
}

if (isset($cfg['Order']['Flags']['D']) && $cfg['Order']['Flags']['D'] === false) {
    unset($cfg['Order']['Flags']['D']);
} elseif (!isset($cfg['Order']['Flags']['D'])) {
    $cfg['Order']['Flags']['D'] = ['name' => 'Duplicitní'];
}

if (!empty($cfg['Modules']['autopilot']) && !isset($cfg['Order']['Flags']['ZA'])) {
    $cfg['Order']['Flags']['ZA'] = ['name' => 'Zpracoval autopilot'];
}

if (!empty($cfg['Modules']['heureka_cart']) && !isset($cfg['Order']['Flags']['H'])) {
    $cfg['Order']['Flags']['H'] = ['name' => 'Heureka'];
}

if (!empty($cfg['Modules']['returns']) && !isset($cfg['Order']['Flags']['V'])) {
    $cfg['Order']['Flags']['V'] = ['name' => 'Vratka'];
}

if (!empty($cfg['Products']['Flags']['N']) && empty($cfg['Products']['Flags']['MN'])) {
    $cfg['Products']['Flags']['MN'] = ['plural' => 'Manuální novinky', 'singular' => 'Manuální novinka', 'short' => 'MN'];
}

if (!empty($cfg['Modules']['returns']) && !isset($cfg['Returns']['Flags']['ZP'])) {
    $cfg['Returns']['Flags']['ZP'] = ['name' => 'Zákaznická podpora'];
}

if (!empty($cfg['Modules']['returns']) && !isset($cfg['Returns']['Flags']['PR'])) {
    $cfg['Returns']['Flags']['PR'] = ['name' => 'Přijato s problémem'];
}

if (!empty($cfg['Modules']['kafka'])) {
    $kafka = &$cfg['Modules']['kafka'];
    $defaultTopics = [
        'default' => [
            'db_changes' => 'products|products_variations|parameters_products|products_in_sections|pricelists_products|price_levels_products|products_of_suppliers|product_labels_relation|stores_items|warehouse_products|products_in_sections_positions|products_variations_choices_categorization|photos_products_relation',
        ],
    ];

    if (!empty($cfg['Modules']['graphql'])) {
        $defaultTopics['graphql'] = [
            'db_changes' => 'products|products_variations|parameters_products|pricelists_products|stores_items|orders|order_items|users|bonus_points',
        ];
    }

    $kafka = is_array($kafka) ? $kafka : [];

    $kafka['topics'] = array_merge($defaultTopics, is_array($kafka['topics'] ?? '') ? $kafka['topics'] : []);
}

if (!isset($cfg['Modules']['llm'])) {
    $cfg['Modules']['llm'] = true;
}

if (!empty($cfg['Modules']['llm'])) {
    $llm = &$cfg['Modules']['llm'];
    $llm = is_array($llm) ? $llm : [
        'provider' => 'openAI',
    ];
}

/*
 * Nastaveni spolecnych velikosti fotek
 */

$PhotoTypes = [
    'admin' => [
        'size' => [64, 48],
    ],
    'default_feed' => [
        'size' => [1200, 1200],
    ],
    'slider' => [
        'size' => [9999, 9999],
        'upscale' => false,
        'quality' => 85,
        'lang' => true,
    ],
    'blocek_small' => [
        'size' => [300, 300],
        'crop' => 'scale',
        'png' => true,
    ],
    'blocek_medium' => [
        'size' => [600, 600],
        'crop' => 'scale',
        'png' => true,
    ],
    'blocek_large' => [
        'size' => [1000, 1000],
        'crop' => 'scale',
        'png' => true,
    ],
    'blocek_big' => [
        'size' => [1920, 1920],
        'crop' => 'scale',
        'png' => true,
    ],
    'facebook_share' => [
        'size' => [1200, 630],
    ],
    'return_delivery' => &$cfg['Photo']['types']['delivery'],
];

$PhotoIdToType = [
    5 => 'admin',
    101 => 'facebook_feed',
    102 => 'default_feed',
    103 => 'slider',
    104 => 'blocek_small',
    105 => 'blocek_medium',
    106 => 'blocek_large',
    107 => 'blocek_big',
    108 => 'facebook_share',
    109 => 'return_delivery',
];

$cfg['Photo']['types'] = $cfg['Photo']['types'] + $PhotoTypes;
$cfg['Photo']['id_to_type'] = $cfg['Photo']['id_to_type'] + $PhotoIdToType;
