import { z } from 'zod';
import { SubscriptionTier } from '../config/billing.config';

export const SubscriptionModel = z.object({
  id: z.string(),
  userId: z.string(),
  stripeSubscriptionId: z.string(),
  stripeCustomerId: z.string(),
  tier: z.nativeEnum(SubscriptionTier),
  status: z.enum(['active', 'canceled', 'in_trial', 'past_due', 'unpaid', 'incomplete']),
  currentPeriodStart: z.date(),
  currentPeriodEnd: z.date(),
  cancelAtPeriodEnd: z.boolean().default(false),
  createdAt: z.date(),
  updatedAt: z.date(),
});

export type Subscription = z.infer<typeof SubscriptionModel>;

export const SubscriptionCreateSchema = z.object({
  userId: z.string(),
  tier: z.nativeEnum(SubscriptionTier),
  stripeCustomerId: z.string(),
  stripeSubscriptionId: z.string(),
  currentPeriodStart: z.date(),
  currentPeriodEnd: z.date(),
});

export const SubscriptionUpdateSchema = z.object({
  tier: z.nativeEnum(SubscriptionTier).optional(),
  status: z.enum(['active', 'canceled', 'in_trial', 'past_due', 'unpaid', 'incomplete']).optional(),
  cancelAtPeriodEnd: z.boolean().optional(),
  currentPeriodStart: z.date().optional(),
  currentPeriodEnd: z.date().optional(),
});
