import { type PaymentStatus } from '@prisma/client';
import { type PaymentEntity } from '../entities/payment.entity';

export const PAYMENT_REPOSITORY = Symbol('PAYMENT_REPOSITORY');

export interface IPaymentRepository {
  findById(id: string): Promise<PaymentEntity | null>;
  findByProviderTxId(providerTxId: string): Promise<PaymentEntity | null>;
  findByIdempotencyKey(key: string): Promise<PaymentEntity | null>;
  findByUserId(userId: string, options?: {
    status?: PaymentStatus;
    limit?: number;
    offset?: number;
  }): Promise<{ items: PaymentEntity[]; total: number }>;
  save(payment: PaymentEntity): Promise<void>;
  update(payment: PaymentEntity): Promise<void>;
  /** Atomically update payment status only if it is currently in one of the expected statuses. Returns null if no matching row. */
  updateIfStatus(id: string, expectedStatuses: PaymentStatus[], data: { status: PaymentStatus; providerTxId?: string; callbackData?: unknown }): Promise<PaymentEntity | null>;
}
