import { z } from 'zod';

/**
 * Model preference configuration
 */
export const ModelPreferenceSchema = z.object({
  provider: z.enum(['anthropic', 'openai', 'google', 'openrouter']),
  model: z.string(),
  temperature: z.number().optional(),
});

export type ModelPreference = z.infer<typeof ModelPreferenceSchema>;

/**
 * User license and feature authorization
 */
export const UserLicenseSchema = z.object({
  userId: z.string(),
  email: z.string().email().optional(),
  licenseType: z.enum(['free', 'pro', 'enterprise']),
  features: z.object({
    maxIndicators: z.number(),
    maxStrategies: z.number(),
    maxBacktestDays: z.number(),
    realtimeData: z.boolean(),
    customExecutors: z.boolean(),
    apiAccess: z.boolean(),
  }),
  resourceLimits: z.object({
    maxConcurrentSessions: z.number(),
    maxMessagesPerDay: z.number(),
    maxTokensPerMessage: z.number(),
    rateLimitPerMinute: z.number(),
  }),
  mcpServerUrl: z.string().url(),
  preferredModel: ModelPreferenceSchema.optional(),
  expiresAt: z.date().optional(),
  createdAt: z.date(),
  updatedAt: z.date(),
});

export type UserLicense = z.infer<typeof UserLicenseSchema>;

/**
 * Channel types for multi-channel support
 */
export enum ChannelType {
  WEBSOCKET = 'websocket',
  TELEGRAM = 'telegram',
  SLACK = 'slack',
  DISCORD = 'discord',
}

/**
 * Authentication context per channel
 */
export const AuthContextSchema = z.object({
  userId: z.string(),
  channelType: z.nativeEnum(ChannelType),
  channelUserId: z.string(), // Platform-specific ID (telegram_id, discord_id, etc)
  sessionId: z.string(),
  license: UserLicenseSchema,
  authenticatedAt: z.date(),
});

export type AuthContext = z.infer<typeof AuthContextSchema>;
