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

import { z } from 'zod';

export interface InvitationCodeDoc {
  id: string;
  productId: string;
  code: string;
  description: string;
  createdBy: string;
  grantPlan: 'pro' | 'enterprise';
  grantTrialDays: number;
  bonusTokens: number;
  maxUses: number;
  currentUses: number;
  redeemedBy: string[];
  status: 'active' | 'expired' | 'disabled';
  expiresAt: string | null;
  createdAt: string;
  updatedAt: string;
}

export const CreateInvitationSchema = z.object({
  code: z.string().min(3).max(50),
  description: z.string().default(''),
  createdBy: z.string().min(1),
  grantPlan: z.enum(['pro', 'enterprise']),
  grantTrialDays: z.number().int().min(0).default(0),
  bonusTokens: z.number().int().min(0).default(0),
  maxUses: z.number().int().min(1).default(1),
  expiresAt: z.string().nullable().default(null),
});

export const UpdateInvitationSchema = z.object({
  description: z.string().optional(),
  grantPlan: z.enum(['pro', 'enterprise']).optional(),
  grantTrialDays: z.number().int().min(0).optional(),
  bonusTokens: z.number().int().min(0).optional(),
  maxUses: z.number().int().min(1).optional(),
  status: z.enum(['active', 'expired', 'disabled']).optional(),
  expiresAt: z.string().nullable().optional(),
});

export const RedeemInvitationSchema = z.object({
  code: z.string().min(1),
  userId: z.string().min(1),
});

export type CreateInvitationInput = z.infer<typeof CreateInvitationSchema>;
export type UpdateInvitationInput = z.infer<typeof UpdateInvitationSchema>;
export type RedeemInvitationInput = z.infer<typeof RedeemInvitationSchema>;
