/**
 * License key types — ported from Python backend license routes.
 * Key format: LYSNR-XXXX-XXXX-XXXX (uppercase alphanumeric).
 */

import { z } from 'zod';

export interface LicenseDoc {
  id: string;
  productId: string;
  key: string;
  userId: string;
  plan: 'free' | 'pro' | 'enterprise';
  status: 'active' | 'revoked' | 'expired';
  activatedAt: string | null;
  expiresAt: string | null;
  deviceIds: string[];
  maxDevices: number;
  createdAt: string;
  updatedAt: string;
}

export const GenerateLicenseSchema = z.object({
  userId: z.string().min(1),
  plan: z.enum(['free', 'pro', 'enterprise']),
  maxDevices: z.number().int().min(1).default(3),
  expiresAt: z.string().nullable().default(null),
});

export const ActivateLicenseSchema = z.object({
  key: z.string().min(1),
  deviceId: z.string().min(1),
  deviceName: z.string().max(100).optional(),
  platform: z.string().max(20).optional(),
});

export const DeactivateLicenseSchema = z.object({
  key: z.string().min(1),
  deviceId: z.string().min(1),
});

export type GenerateLicenseInput = z.infer<typeof GenerateLicenseSchema>;
export type ActivateLicenseInput = z.infer<typeof ActivateLicenseSchema>;
