from __future__ import absolute_import, division, print_function, unicode_literals

FX_SPOT_SETTLEMENT_CYCLE = {
'AED':2,
'AFN':2,
'ALL':2,
'AMD':2,
'ANG':2,
'AOA':2,
'ARS':2,
'AUD':2,
'AWG':2,
'AZN':0,
'BAM':2,
'BBD':2,
'BDT':2,
'BGN':2,
'BHD':2,
'BIF':2,
'BMD':2,
'BND':2,
'BOB':2,
'BRL':2,
'BSD':2,
'BTN':2,
'BWP':2,
'BYR':0,
'BZD':2,
'CAD':1,
'CDF':2,
'XAF':2,
'CHF':2,
'CLP':2,
'CNH':2,
'CNY':2,
'COP':2,
'CRC':2,
'CUP':2,
'CVE':2,
'CZK':2,
'DJF':2,
'DKK':2,
'DOP':2,
'DZD':2,
'ECS':2,
'EGP':2,
'ERN':2,
'ETB':2,
'EUR':2,
'FJD':2,
'FKP':2,
'GBP':2,
'GEL':2,
'GHS':2,
'GIP':2,
'GMD':2,
'GNF':2,
'GTQ':2,
'GYD':2,
'HKD':2,
'HNL':2,
'HRK':2,
'HTG':2,
'HUF':2,
'IDR':2,
'ILS':2,
'INR':2,
'IQD':2,
'ISK':2,
'JMD':2,
'JOD':2,
'JPY':2,
'KES':2,
'KGS':0,
'KHR':2,
'KRW':2,
'KWD':2,
'KYD':2,
'KZT':0,
'LAK':2,
'LBP':2,
'LKR':2,
'LRD':2,
'LSL':2,
'LYD':2,
'MAD':2,
'MDL':0,
'MGA':2,
'MKD':2,
'MMK':2,
'MNT':0,
'MOP':2,
'MRO':2,
'MUR':2,
'MVR':2,
'MWK':2,
'MXN':2,
'MYR':2,
'MZN':2,
'NAD':2,
'NGN':2,
'NIO':2,
'NOK':2,
'NPR':2,
'NZD':2,
'OMR':2,
'PAB':2,
'PEN':2,
'XPF':2,
'PGK':2,
'PHP':1,
'PKR':2,
'PLN':2,
'PYG':2,
'QAR':2,
'RON':2,
'RSD':2,
'RUB':1,
'RWF':2,
'SAR':2,
'SBD':2,
'SCR':2,
'SEK':2,
'SGD':2,
'SHP':2,
'SLL':2,
'SOS':2,
'SRD':2,
'STD':2,
'SVC':2,
'SZL':2,
'THB':2,
'TJS':2,
'TND':2,
'TOP':2,
'TRY':1,
'TTD':2,
'TWD':2,
'TZS':2,
'UAH':2,
'UGX':2,
'UYU':2,
'UZS':2,
'VEF':2,
'VND':2,
'VUV':2,
'WST':2,
'YER':2,
'ZAR':2,
'ZMW':2,
}

FX_SPOT_CROSS_SETTLEMENT_CYCLE = {
    'RUBBYR': 0,
    'EURBYR': 0,
    'CLPCLF': 0,
    'EURAZN': 0,
    'AZNRUB': 0,
    'MNTCAD': 1,
    'MNTPHP': 1,
    'MNTTRY': 1,
    'MNTTRL': 1,
    'RUBMMK': 2,
    'RUBDKK': 2,
    'RUBSEK': 2,
    'RUBNOK': 2,
    'RUBGBP': 2,
    'CADPHP': 1,
    'CADTRY': 1,
    'CADTRL': 1,
    'PHPTRY': 1,
    'PHPTRL': 1,
    'PHPTRY': 1,
    'TRYTRL': 1
}

def get_settlement_day_convention(base_currency,pricing_currency):
    """

    input: currency ticker, e.g. base_currency = 'USD', pricing_currency = 'JPY'
    return: int 0, 1 or 2 (to represent T+0, T+1 or T+2)

    Settlement Conventions 
    • USDMNT, USDBYR, RUBBYR, EURBYR, USDMDL, USDKZT, USDKGS, CLPCLF, USDAZN, EURAZN, and AZNRUB settle T+0.
    • CAD, PHP, TRY, and TRL settle T+1 against USD, against MNT, and against each other.
    • RUB settles T+1 against all currencies except MMK, DKK, SEK, NOK, and GBP, against all of which it settles T+2.
    • All other currencies settle T+2 against USD.

    """
    if base_currency == 'USD' or pricing_currency == 'USD':
        return FX_SPOT_SETTLEMENT_CYCLE.get(pricing_currency if base_currency == 'USD' else base_currency)

    if base_currency + pricing_currency in FX_SPOT_CROSS_SETTLEMENT_CYCLE: 
        return FX_SPOT_CROSS_SETTLEMENT_CYCLE.get(base_currency + pricing_currency)
    if pricing_currency + base_currency in FX_SPOT_CROSS_SETTLEMENT_CYCLE:
        return FX_SPOT_CROSS_SETTLEMENT_CYCLE.get(pricing_currency + base_currency)
                
    if base_currency == 'RUB' or pricing_currency == 'RUB':
        return 1
    return 2

