import {
  TrackedAddressRecord,
  UserMapping,
  WalletMappingInput,
  WebhookShardMetadata,
} from "../types";
import { PendingBlinkInvoiceRecord } from "../providers/blink/types";
import { IRegisteredAddressPort } from "../providers/ProviderPorts";

export interface IMappingStore {
  // Historical naming note:
  // "userId" here is currently the wallet derivation identity key used to keep
  // HD-derived wallets unique. It is not intended to be an application user id
  // or organization id for payment-wallet generation.
  getByUserId(userId: number): Promise<UserMapping | null>;
  upsertUserMapping(userId: number, wallets: WalletMappingInput[]): Promise<UserMapping>;
  getByTrackedAddress(address: string): Promise<{ userId: number; wallet: WalletMappingInput } | null>;
  getWalletsByChainType(chainType: string): Promise<Array<{ user_id: number; wallet: WalletMappingInput }>>;
}

export interface ITrackingStore extends IRegisteredAddressPort {
  getAllTrackedAddresses(): Promise<Array<{ chainType: string; address: string }>>;
  getAllShards(): Promise<WebhookShardMetadata[]>;
  getShardByWebhookId(webhookId: string): Promise<WebhookShardMetadata | null>;
  getAddress(address: string): Promise<TrackedAddressRecord | null>;
  getShardsByChainType(chainType: string): Promise<WebhookShardMetadata[]>;
  upsertShards(shards: WebhookShardMetadata[]): Promise<void>;
  registerAssignments(assignments: TrackedAddressRecord[]): Promise<void>;
  unregisterAddresses(addresses: string[]): Promise<void>;
}

export interface IBlinkInvoiceStore {
  savePending(record: PendingBlinkInvoiceRecord): Promise<void>;
  findPendingByPaymentHashOrReference(
    paymentHash?: string,
    reference?: string
  ): Promise<PendingBlinkInvoiceRecord | null>;
  markConfirmed(
    reference: string,
    providerReference: string | undefined,
    transactionStatus: string,
    walletCurrency: string,
    rawWebhookPayload: Record<string, unknown>
  ): Promise<void>;
}
