<?php
namespace ccxt;

// ----------------------------------------------------------------------------

// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code

// -----------------------------------------------------------------------------


function helper_test_handle_market_type_and_params() {
    $exchange = new \ccxt\Exchange(array(
        'id' => 'sampleexchange',
        'options' => array(
            'defaultType' => 'valueFromOptions',
            'fetchX' => array(
                'defaultType' => 'valueFromMethodOptions',
            ),
        ),
    ));
    $initial_params = array(
        'defaultType' => 'valueFromParam',
    );
    $market = $exchange->safe_market('TEST1/TEST2');
    $market['type'] = 'spot';
    //
    // ########### test different variations ###########
    //
    // case #1, should prevail: param
    //
    [$market_type_1, $params1] = $exchange->handle_market_type_and_params('fetchX', $market, $initial_params, 'valueDefault');
    assert(is_array($initial_params) && array_key_exists('defaultType', $initial_params));
    assert(!(is_array($params1) && array_key_exists('defaultType', $params1)));
    assert($market_type_1 === 'valueFromParam');
    //
    // case #2, should prevail: market.type
    //
    [$market_type_2, $params2] = $exchange->handle_market_type_and_params('fetchX', $market, array(), 'valueDefault');
    assert($market_type_2 === 'spot');
    //
    // case #3, should prevail: valueDefault
    //
    [$market_type_3, $params3] = $exchange->handle_market_type_and_params('fetchX', null, array(), 'valueDefault');
    assert($market_type_3 === 'valueDefault');
    //
    // case #4, should prevail: method options
    //
    [$market_type_4, $params4] = $exchange->handle_market_type_and_params('fetchX', null, array());
    assert($market_type_4 === 'valueFromMethodOptions');
    //
    // case #5, should prevail: options
    //
    [$market_type_5, $params5] = $exchange->handle_market_type_and_params('fetchY', null, array(), null);
    assert($market_type_5 === 'valueFromOptions');
    //
    // case #6, should prevail: spot (because hardcoded in base)
    //
    $exchange->options['defaultType'] = null;
    [$market_type_6, $params6] = $exchange->handle_market_type_and_params('fetchY', null, array(), null);
    assert($market_type_6 === 'spot');
    // fake assertion to avoid unused vars
    assert($params1 !== null || $params2 !== null || $params3 !== null || $params4 !== null || $params5 !== null || $params6 !== null);
}


function helper_test_handle_network_request() {
    $exchange = new \ccxt\Exchange(array(
        'id' => 'sampleexchange',
        'options' => array(
            'networks' => array(
                'XYZ' => 'Xyz',
            ),
        ),
    ));
    $exchange->currencies = $exchange->create_safe_dictionary(); // todo: initialize in C# base files
    $currency_code = 'ETH'; // todo: in future with complex cases
    // no-case
    [$request1, $params1] = $exchange->handle_request_network(array(
        'network' => 'XYZ',
    ), array(), 'chain_id', $currency_code, false);
    assert(!(is_array($params1) && array_key_exists('network', $params1)));
    assert(is_array($request1) && array_key_exists('chain_id', $request1));
    assert($request1['chain_id'] === 'Xyz');
}


function test_handle_methods() {
    helper_test_handle_market_type_and_params();
    helper_test_handle_network_request();
}
