"""
Payment Request specific enums.

This module contains all enums specific to the payment requests functionality,
moved from core.utils.enums for better modularity and organization.
"""

from enum import Enum, IntEnum
from typing import Any, Dict


class WellDocumentedIntEnum(IntEnum):
    @classmethod
    def __get_pydantic_json_schema__(cls, _core_schema, handler):
        """Generate JSON schema for Pydantic v2 compatibility."""
        json_schema = handler(_core_schema)
        
        # Add enum descriptions while maintaining proper schema structure
        if hasattr(cls, '_descriptions'):
            descriptions = {}
            for member in cls:
                member_name = member.name
                member_value = member.value
                if member_name in cls._descriptions:
                    descriptions[str(member_value)] = cls._descriptions[member_name]
            
            if descriptions:
                if 'enum' in json_schema:
                    json_schema['enumDescriptions'] = descriptions
        
        return json_schema

    def __int__(self) -> int:
        return self.value

    @classmethod
    def list(cls) -> Dict[str, Any]:
        """Return a dictionary of enum name -> value mappings"""
        return {member.name: member.value for member in cls}


class PaymentCurrencies(str, Enum):
    """PaymentCurrencies"""

    AUD = "aud"
    CAD = "cad"
    DKK = "dkk"
    EUR = "eur"
    HKD = "hkd"
    JPY = "jpy"
    NZD = "nzd"
    NOK = "nok"
    GBP = "gbp"
    ZAR = "zar"
    SEK = "sek"
    CHF = "chf"
    USD = "usd"


class PaymentFrequencies(str, Enum):
    """Message Status"""

    SPLIT = "split"
    RECURRING = "recurring"
    ONE_TIME = "one_time"


class PaymentAuthorizationTypes(str, Enum):
    """Message Status"""

    PRE_AUTH = "pre_auth"
    REQUEST_AUTH = "request_auth"


class PaymentRequestStatusTypes(WellDocumentedIntEnum):
    """Payment Request Status"""

    CREATED = 100  # when just created and payment not started
    UPDATED = 101  # if payment request is updated.
    DRAFT = 102  # if payment request is saved as draft
    WAITING = 200  # If payment request is waiting to be approved by customer (HPP only)
    UPCOMING = 201  # when invoice is created (before 7 days of payment)
    RETRYING = 202  # when payment request is being retried
    AWAITING_APPROVAL = 203
    CAPTURED = 204
    AUTHORISED = 300  # If the customer has authorised the payment request
    PROCESSING = 400  # when payment is in process
    PAID = 500  # if payment successfull and no more payment required
    PARTIALLY_PAID = 501  # if payment successfull, but more payments required
    STALLED = 502  # when payment request is stalled by the merchant
    FAILED = 600  # if payment fails for any other reason than payment method
    OVERDUE = 601  # if payment due date exceeded, nad payment has not been made yet
    UNCOLLECTIBLE = 602  # if payment method is invalid and cannot be used
    CANCELLED = 700  # if payment req is cancelled by merchant
    DECLINED = 701  # if payment was declined by customer (Only for HPP)
    REFUNDED = 800  # if the payment was refunded
    EXPIRED = 900  # If the payment request is expired and cannot be used anymore


class SplitPaymentTypes(str, Enum):
    """Message Status"""

    PERCENTAGE = "percentage"
    AMOUNT = "amount"


class DiscountTypes(str, Enum):
    """Message Status"""

    PERCENTAGE = "percentage"
    AMOUNT = "amount"


class TaxType(str, Enum):
    """Tax Type Inclusive/Exclusive"""

    EXCLUSIVE = "tax_exclusive"
    INCLUSIVE = "tax_inclusive"
    NOTAX = "notax"


class SurchargeTypes(str, Enum):
    """Message Status"""

    EXCLUSIVE = "exclusive"
    INCLUSIVE = "inclusive"


class RecurringPaymentIntervals(str, Enum):
    """Message Status"""

    DAY = "day"
    WEEK = "week"
    MONTH = "month"
    QUARTER = "quarter"
    YEAR = "year"


class RecurringPaymentEndTypes(str, Enum):
    """Message Status"""

    DATE = "date"
    UNTIL_COUNT = "until_count"
    UNTIL_CANCELLED = "until_cancelled"
    NEVER = "never"


class RecurringPaymentRepeatTypes(str, Enum):
    """RecurringPaymentRepeatTypes"""

    ON_DATE = "on_date"
    ON_PERIOD = "on_period"
    DAY_OF_MONTH = "day_of_month"
    TIME_OF_MONTH = "time_of_month"
    INTERVAL = "interval"
    CUSTOM_INTERVAL = "custom_interval"