/**
 * Referral types — consolidated from admin + user dashboard repos.
 */

import { z } from 'zod';

export interface ReferralDoc {
  id: string;
  productId: string;
  referrerId: string;
  referrerEmail: string;
  referredUserId: string | null;
  referredEmail: string;
  status: 'pending' | 'signed_up' | 'subscribed' | 'rewarded';
  referrerRewardTokens: number;
  referredRewardTokens: number;
  referrerRewarded: boolean;
  referredRewarded: boolean;
  createdAt: string;
  completedAt: string | null;
}

export const CreateReferralSchema = z.object({
  referrerId: z.string().min(1),
  referrerEmail: z.string().email(),
  referredEmail: z.string().email(),
  referrerRewardTokens: z.number().int().min(0).default(1000),
  referredRewardTokens: z.number().int().min(0).default(500),
});

export const UpdateReferralStatusSchema = z.object({
  status: z.enum(['pending', 'signed_up', 'subscribed', 'rewarded']),
  referredUserId: z.string().optional(),
  referrerRewarded: z.boolean().optional(),
  referredRewarded: z.boolean().optional(),
});

export type CreateReferralInput = z.infer<typeof CreateReferralSchema>;
export type UpdateReferralStatusInput = z.infer<typeof UpdateReferralStatusSchema>;
