from __future__ import annotations

import stripe

from src.core.config import settings

stripe.api_key = settings.STRIPE_SECRET_KEY


def create_payment_intent(
    amount_cents: int,
    currency: str,
    metadata: dict[str, str],
) -> stripe.PaymentIntent:
    return stripe.PaymentIntent.create(
        amount=amount_cents,
        currency=currency.lower(),
        metadata=metadata,
        automatic_payment_methods={"enabled": True},
    )


def construct_event(payload: bytes, sig_header: str) -> stripe.Event:
    return stripe.Webhook.construct_event(
        payload, sig_header, settings.STRIPE_WEBHOOK_SECRET
    )
