import type {
  ClubMember,
  ClubRecoveryCode,
  ClubResolveInput,
  ClubSettings,
  ClubTransaction,
  LinkMemberResult,
  MergeMembersResult,
  RecordClubTransactionCommand,
  RecordClubTransactionResult,
  UpdateClubSettingsCommand,
} from './club.js';

export interface CreateClubMemberCommand {
  memberCode: string;
  deviceTokenHash: string;
  userId?: string | null;
}

export interface ClubRepository {
  getSettings(): Promise<ClubSettings>;
  updateSettings(input: UpdateClubSettingsCommand, updatedBy: string | null): Promise<ClubSettings>;
  createMemberWithDevice(input: CreateClubMemberCommand): Promise<ClubMember | null>;
  findMemberByUserId(userId: string): Promise<ClubMember | null>;
  findMemberByDeviceTokenHash(hash: string, touch?: boolean): Promise<ClubMember | null>;
  findMemberByCode(code: string): Promise<ClubMember | null>;
  resolveMember(input: ClubResolveInput & { deviceTokenHash?: string | null }): Promise<ClubMember | null>;
  listTransactions(memberId: string, limit: number): Promise<ClubTransaction[]>;
  recordTransaction(input: RecordClubTransactionCommand): Promise<RecordClubTransactionResult>;

  // Recovery codes
  generateRecoveryCodes(memberId: string, count: number, expiresInDays: number): Promise<{ code: string; fingerprint: string; expiresAt: Date }[]>;
  listActiveRecoveryCodes(memberId: string): Promise<ClubRecoveryCode[]>;
  consumeRecoveryCode(fingerprint: string, newDeviceTokenHash: string): Promise<{ memberId: string; fingerprint: string }>;

  // Member linking and merging
  linkMemberToUser(memberId: string, userId: string): Promise<LinkMemberResult>;
  mergeMembers(primaryMemberId: string, mergedMemberId: string): Promise<MergeMembersResult>;
}
