export type PaymentType = 'card' | 'eps'

export enum PaymentProvider {
	Stripe = 'stripe',
	Coinbase = 'coinbase',
	PayPal = 'paypal',
	Braintree = 'braintree',
	OpenPayment = 'open-payment',
}

export interface CreatePaymentQuery {
	orderId: number
	type?: PaymentType
}

export interface StripeConfig {
	publishableKey: string
}

export interface PaymentAmount<T> {
	amount: number
	currency: string
	metadata?: T
}

export interface CryptoPaymentMeta {
	redirectUrl?: string
	cancelUrl?: string
	name?: string
	description?: string
}

export interface CryptoPayment {
	id: string
	hostedUrl: string
	expiresAt: string
	addresses: Record<string, string>
}

/**
 * @param publishableKey Stripe publishable key
 * @param paymentIntent Stripe's payment intent object
 */
export interface PaymentIntentResponse extends StripeConfig {
	paymentIntent: PaymentIntent
}

export interface PaymentIntent {
	id: string
	object: 'payment_intent'
	amount: number
	amountCapturable: number
	amountReceived: number
	captureMethod: string
	charges: Charges
	clientSecret: string
	confirmationMethod: string
	created: number
	currency: string
	description: string
	livemode: boolean
	metadata: Metadata
	nextAction: null
	onBehalfOf: null
	paymentMethod: null
	paymentMethodOptions: any
	paymentMethodTypes: PaymentType[]
	status: string
}

export interface Charges {
	object: 'list'
	data: any[]
	hasMore: boolean
	url: string
}

/**
 * @param id order id
 * @param enrollmentId user's enrollment id
 */
export interface Metadata {
	id: string
	enrollmentId: string
}

export interface IPayoutData {
	senderBatchId: string
	emailSubject?: string
	emailMessage?: string
	items: IPayoutItem[]
}

export interface IPayoutItem {
	amount: MoneyAmount
	senderItemId: string
	receiver: string
}

/**
 * @param currency ISO 4217 currency code.
 * @param value The amount of money.
 */
export type MoneyAmount = {
	currency: string
	value: string
}

export interface IPayout {
	payoutBatchId: string
	batchStatus: BatchStatus
	senderBatchId: string
}

/**
 * See more at https://developer.paypal.com/docs/api/payments.payouts-batch/v1/#definition-batch_enum
 */
export enum BatchStatus {
	Denied = 'DENIED', // Your payout requests were denied, so they were not processed. Check the error messages to see any steps necessary to fix these issues.
	Pending = 'PENDING', // Your payout requests were received and will be processed soon.
	Processing = 'PROCESSING', // Your payout requests were received and are now being processed.
	Success = 'SUCCESS', // Your payout batch was processed and completed. Check the status of each item for any holds or unclaimed transactions.
	Canceled = 'CANCELED', // The payouts file that was uploaded through the PayPal portal was cancelled by the sender.
}

export interface OpenPaymentMeta {
	redirectUrl?: string
	billing?: {
		street1: string
		city: string
		state: string
		country: string
		postcode: string
	}
	customer?: {
		email: string
		givenName: string
		surname: string
	}
}

export interface OpenPaymentResponse {
	id: string
	timestamp: string
}

export interface OpenPaymentOrderData {
	metadata: OpenPaymentMeta
}
export interface OpenPaymentOrderQuery {
	orderId: number
}
