"""The driver taxonomy, written before any classifier ran: six contact drivers, the dataset's 77 intents grouped into
them, and the two prompt versions. Nothing here reads the data."""

DRIVERS = ('A', 'B', 'C', 'D', 'E', 'F')
DRIVER_NAMES = {
    'A': 'Getting a card',
    'B': 'Something failed or is stuck',
    'C': 'Fees and exchange rates',
    'D': 'Fraud, disputes and money back',
    'E': 'Identity and account access',
    'F': 'How-to and product questions',
}
DRIVER_DEFINITIONS = {
    'A': 'ordering, delivery, activation, linking or replacing a card, including virtual and extra cards.',
    'B': 'a payment, transfer, top-up or withdrawal that was declined, is pending, failed, was reverted or has not '
         'arrived; a card or a balance that is not working as it should.',
    'C': 'a charge, fee or exchange rate the customer asks about or disagrees with.',
    'D': 'an unrecognised or duplicated transaction, a lost, stolen or compromised card or phone, a refund, cancelling '
         'a transfer, or receiving the wrong amount of cash.',
    'E': 'verifying identity or source of funds, a verification code, a PIN or passcode, personal details, or closing '
         'the account.',
    'F': 'what is supported, where and how something works, limits, and the ways to top up or to send and receive money.',
}

# The dataset's own intent names, unchanged, grouped by driver.
GROUPS = {
    'A': ('activate_my_card', 'card_about_to_expire', 'card_arrival', 'card_delivery_estimate', 'card_linking',
          'get_disposable_virtual_card', 'get_physical_card', 'getting_spare_card', 'getting_virtual_card',
          'order_physical_card'),
    'B': ('balance_not_updated_after_bank_transfer', 'balance_not_updated_after_cheque_or_cash_deposit',
          'beneficiary_not_allowed', 'card_not_working', 'card_swallowed', 'contactless_not_working',
          'declined_card_payment', 'declined_cash_withdrawal', 'declined_transfer', 'failed_transfer',
          'pending_card_payment', 'pending_cash_withdrawal', 'pending_top_up', 'pending_transfer',
          'reverted_card_payment?', 'top_up_failed', 'top_up_reverted', 'transfer_not_received_by_recipient',
          'virtual_card_not_working'),
    'C': ('card_payment_fee_charged', 'card_payment_wrong_exchange_rate', 'cash_withdrawal_charge', 'exchange_charge',
          'exchange_rate', 'extra_charge_on_statement', 'top_up_by_bank_transfer_charge', 'top_up_by_card_charge',
          'transfer_fee_charged', 'wrong_exchange_rate_for_cash_withdrawal'),
    'D': ('Refund_not_showing_up', 'cancel_transfer', 'card_payment_not_recognised', 'cash_withdrawal_not_recognised',
          'compromised_card', 'direct_debit_payment_not_recognised', 'lost_or_stolen_card', 'lost_or_stolen_phone',
          'request_refund', 'transaction_charged_twice', 'wrong_amount_of_cash_received'),
    'E': ('change_pin', 'edit_personal_details', 'passcode_forgotten', 'pin_blocked', 'terminate_account',
          'unable_to_verify_identity', 'verify_my_identity', 'verify_source_of_funds', 'verify_top_up',
          'why_verify_identity'),
    'F': ('age_limit', 'apple_pay_or_google_pay', 'atm_support', 'automatic_top_up', 'card_acceptance',
          'country_support', 'disposable_card_limits', 'exchange_via_app', 'fiat_currency_support', 'receiving_money',
          'supported_cards_and_currencies', 'top_up_by_cash_or_cheque', 'top_up_limits', 'topping_up_by_card',
          'transfer_into_account', 'transfer_timing', 'visa_or_mastercard'),
}
INTENT_TO_DRIVER = {intent: d for d, group in GROUPS.items() for intent in group}

_INTRO = ('You label customer-support messages sent to an online bank with the reason for the contact, called the driver. '
          'The drivers are:')
_RULES = ('Each message gets exactly one driver. If two seem to fit, choose the one that names what the customer needs '
          'done now.\nReply with one line per message, in the form number,letter. Write nothing else.')


def system_prompt(version):
    """Version 1 gives each driver's name and definition. Version 2 is the same prompt with the definitions deleted, the
    one change a prompt clean-up could plausibly make."""
    if version == 1:
        lines = [f'{d} {DRIVER_NAMES[d]}: {DRIVER_DEFINITIONS[d]}' for d in DRIVERS]
    elif version == 2:
        lines = [f'{d} {DRIVER_NAMES[d]}' for d in DRIVERS]
    else:
        raise ValueError(version)
    return _INTRO + '\n' + '\n'.join(lines) + '\n' + _RULES


def user_prompt(texts):
    """The messages of one batch, numbered from 1. Numbers carry no information about the dataset's order."""
    return '\n'.join(f'{i}. ' + ' '.join(t.split()) for i, t in enumerate(texts, 1))
