import { CoursePurchaseStatus } from "@/lib/interfaces/course/course.interface"
import { PaymentMethod } from "@/lib/enums/payment-method.enum"

export interface PaymentMethodOption {
    key: PaymentMethod
    label: string
    color: string
    enabled: boolean
    unavailability_reason: string | null
}

export interface PaymentGatewayOption {
    key: string
    label: string
    enabled: boolean
}

export interface PurchasePaymentDto {
    methods: PaymentMethodOption[]
    gateways: PaymentGatewayOption[]
}

// Fields specific to a "course" purchasable - mirrors the backend's Course::purchasablePreviewDetails().
export interface CoursePurchaseDetails {
    description: string | null
    cover: string | null
    start_date: string | null
    end_date: string | null
    is_purchasable: boolean
}

export interface CritiquePurchaseDetails {
    coach: string | null
    title: string
    note: string | null
    artwork: string | null
    status: string
    is_purchasable: boolean
}

// The purchase preview page's response shape - generic for any purchasable type.
export interface PurchaseDto<D = Record<string, unknown>> {
    id: number
    purchasable_type: string
    title: string
    price: number
    purchase_status: CoursePurchaseStatus | null
    payment_method: PaymentMethod | null
    // ISO datetime a pending IPG payment will auto-expire at - drives the cancel panel's countdown.
    payment_expires_at: string | null
    payment_card: string
    payment: PurchasePaymentDto
    details: D
}

export type PurchaseFetchResponseDto = PurchaseDto<CoursePurchaseDetails | CritiquePurchaseDetails>
