"""
Which payment gateway an install settles through.

Iran has many gateways and the UK has Stripe, so the gateway cannot be a
literal in the pages that display it. PAYMENT_PROVIDER names one of these
keys, and everything else reads the registry. Adding Zarinpal or Mellat later
is a row here plus a checkout flow, with no change to System Info, CRM or
Settings.

'flow' says whether this install can actually take a payment through that
gateway yet. A gateway listed with flow False is a label only: the panel
names it correctly and reports it as not connected rather than pretending.
"""

GATEWAYS = {
    'stripe': {
        'name':   'Stripe',
        'icon':   'fa-brands fa-stripe-s',
        'colour': '#635bff',
        'url':    'https://dashboard.stripe.com/',
        'flow':   True,
    },
    'sep': {
        'name':   'SEP by Bank Saman',
        'icon':   'fa-solid fa-building-columns',
        'colour': '#2555b0',
        'url':    'https://www.sep.ir/',
        'flow':   False,
    },
    'zarinpal': {
        'name':   'ZarinPal',
        'icon':   'fa-solid fa-building-columns',
        'colour': '#ffd700',
        'url':    'https://www.zarinpal.com/',
        'flow':   False,
    },
    'mellat': {
        'name':   'Behpardakht Mellat',
        'icon':   'fa-solid fa-building-columns',
        'colour': '#d32f2f',
        'url':    'https://behpardakht.com/',
        'flow':   False,
    },
    'parsian': {
        'name':   'Parsian',
        'icon':   'fa-solid fa-building-columns',
        'colour': '#f9a825',
        'url':    'https://www.pec.ir/',
        'flow':   False,
    },
}

DEFAULT = 'stripe'


def active_key():
    """The key this install is configured for, always one that exists."""
    from django.conf import settings
    key = (getattr(settings, 'PAYMENT_PROVIDER', '') or DEFAULT).strip().lower()
    return key if key in GATEWAYS else DEFAULT


def active():
    """The gateway record, with its key included."""
    key = active_key()
    data = dict(GATEWAYS[key])
    data['key'] = key
    return data


def is_stripe():
    """True only where Stripe is the gateway.

    Guards every call out to Stripe. Without it an install that settles
    through an Iranian gateway still pings Stripe on page load and shows an
    API key error for a service it will never use.
    """
    return active_key() == 'stripe'
