import { type PaymentProvider } from '@prisma/client';

export const PAYMENT_GATEWAY_FACTORY = Symbol('PAYMENT_GATEWAY_FACTORY');

export interface CreatePaymentUrlParams {
  orderId: string;
  amountVND: bigint;
  description: string;
  /** Frontend redirect URL shown to the user after payment */
  returnUrl: string;
  /** Backend IPN / server-callback URL (overrides PAYMENT_CALLBACK_BASE_URL when provided) */
  callbackUrl?: string;
  ipAddress: string;
}

export interface CreatePaymentUrlResult {
  paymentUrl: string;
  providerTxId: string;
}

export interface CallbackVerifyResult {
  isValid: boolean;
  orderId: string;
  providerTxId: string;
  isSuccess: boolean;
  rawData: Record<string, unknown>;
}

export interface RefundParams {
  providerTxId: string;
  amountVND: bigint;
  reason: string;
}

export interface RefundResult {
  success: boolean;
  refundTxId: string | null;
}

export interface IPaymentGateway {
  readonly provider: PaymentProvider;
  createPaymentUrl(params: CreatePaymentUrlParams): Promise<CreatePaymentUrlResult>;
  verifyCallback(data: Record<string, string>): CallbackVerifyResult;
  refund(params: RefundParams): Promise<RefundResult>;
}

export interface IPaymentGatewayFactory {
  getGateway(provider: PaymentProvider): IPaymentGateway;
}
