it0/it0-web-admin/src/domain/entities/referral.ts

91 lines
2.2 KiB
TypeScript

export type ReferralStatus = 'PENDING' | 'ACTIVE' | 'REWARDED' | 'EXPIRED';
export type RewardStatus = 'PENDING' | 'APPLIED' | 'EXPIRED';
export interface ReferralRelationship {
id: string;
referrerTenantId: string;
referredTenantId: string;
referralCode: string;
level: number;
status: ReferralStatus;
registeredAt: string;
activatedAt: string | null;
rewardedAt: string | null;
}
export interface ReferralReward {
id: string;
beneficiaryTenantId: string;
referralRelationshipId: string;
rewardType: 'CREDIT' | 'PERCENTAGE';
triggerType: 'FIRST_PAYMENT' | 'RECURRING';
amountCents: number;
amountFormatted: string;
status: RewardStatus;
invoiceId: string | null;
sourceInvoiceId: string | null;
recurringMonth: number | null;
createdAt: string;
appliedAt: string | null;
}
export interface ReferralAdminStats {
totalReferrals: number;
activeReferrals: number;
pendingRewards: number;
}
export interface PaginatedResult<T> {
items: T[];
total: number;
}
// ── User-level / personal circle (C2C) ────────────────────────────────────────
export type UserReferralStatus = 'PENDING' | 'ACTIVE' | 'REWARDED' | 'EXPIRED';
export interface UserCircleRelationship {
id: string;
referrerUserId: string;
referredUserId: string;
referralCode: string;
level: number;
status: UserReferralStatus;
activatedAt: string | null;
rewardedAt: string | null;
createdAt: string;
}
export type PointTransactionType =
| 'REFERRAL_FIRST_PAYMENT'
| 'REFERRAL_RECURRING'
| 'REFERRAL_L2'
| 'REFERRAL_WELCOME'
| 'REDEMPTION_QUOTA'
| 'REDEMPTION_UNLOCK'
| 'ADMIN_GRANT'
| 'EXPIRY';
export interface UserPointTransaction {
id: string;
userId: string;
delta: number;
type: PointTransactionType;
refId: string | null;
note: string | null;
createdAt: string;
}
export interface UserPointBalance {
userId: string;
balance: number;
totalEarned: number;
totalSpent: number;
updatedAt: string;
}
export interface ReferralAdminStatsExtended extends ReferralAdminStats {
totalUserCircles: number;
totalPointTransactions: number;
}