export type ClubMemberStatus = 'active' | 'blocked' | 'merged';
export type ClubTransactionType = 'earn' | 'redeem' | 'refund' | 'bonus' | 'adjustment';

export interface ClubMember {
  id: string;
  userId: string | null;
  memberCode: string;
  status: ClubMemberStatus;
  tierCode: string;
  currentBalanceCents: number;
  createdAt: Date;
  updatedAt: Date;
}

export interface ClubTransaction {
  id: string;
  memberId: string;
  saleId: string | null;
  storeId: string | null;
  type: ClubTransactionType;
  amountCents: number;
  balanceDeltaCents: number;
  idempotencyKey: string | null;
  metadata: Record<string, unknown>;
  createdAt: Date;
}

export interface ClubSettings {
  enabled: boolean;
  cashbackBps: number;
  allowAnonymousMembers: boolean;
  allowRecoveryCodes: boolean;
  minimumRedeemAmountCents: number;
}

export const DEFAULT_CLUB_SETTINGS: ClubSettings = {
  enabled: true,
  cashbackBps: 200,
  allowAnonymousMembers: true,
  allowRecoveryCodes: true,
  minimumRedeemAmountCents: 500,
};

export interface ClubResolveInput {
  userId?: string | null;
  deviceToken?: string | null;
}

export interface UpdateClubSettingsCommand {
  enabled?: boolean;
  cashbackBps?: number;
  allowAnonymousMembers?: boolean;
  allowRecoveryCodes?: boolean;
  minimumRedeemAmountCents?: number;
}

export interface RecordClubTransactionCommand {
  memberId: string;
  saleId?: string | null;
  storeId?: string | null;
  type: ClubTransactionType;
  amountCents: number;
  balanceDeltaCents: number;
  idempotencyKey?: string | null;
  metadata?: Record<string, unknown>;
}

export interface JoinClubResult {
  member: ClubMember;
  deviceToken: string;
  created: boolean;
}

export interface RecordClubTransactionResult {
  member: ClubMember;
  transaction: ClubTransaction;
  created: boolean;
}
