export type UserPlan = 'free' | 'pro' | 'business' | 'enterprise';

export type MonitorStatus = 'active' | 'paused' | 'error';

export type MonitorFrequency = 1 | 5 | 30 | 60 | 360 | 1440; // minutes

export type AlertType = 'change' | 'error' | 'keyword';

export type AlertChannel = 'email' | 'slack' | 'webhook';

export interface User {
  id: string;
  email: string;
  passwordHash: string;
  plan: UserPlan;
  stripeCustomerId?: string;
  emailVerified?: boolean;
  emailVerifiedAt?: Date;
  emailEnabled?: boolean;
  webhookUrl?: string;
  webhookEnabled?: boolean;
  slackWebhookUrl?: string;
  slackEnabled?: boolean;
  createdAt: Date;
  lastLoginAt?: Date;
}

export interface IgnoreRule {
  type: 'css' | 'regex' | 'text';
  value: string;
}

export interface KeywordRule {
  keyword: string;
  type: 'appears' | 'disappears' | 'count';
  threshold?: number;
  caseSensitive?: boolean;
}

export interface Monitor {
  id: string;
  userId: string;
  url: string;
  name: string;
  frequency: MonitorFrequency;
  status: MonitorStatus;
  elementSelector?: string;
  ignoreRules?: IgnoreRule[];
  keywordRules?: KeywordRule[];
  lastCheckedAt?: Date;
  lastChangedAt?: Date;
  consecutiveErrors: number;
  createdAt: Date;
  updatedAt: Date;
}

export interface Snapshot {
  id: string;
  monitorId: string;
  htmlContent: string;
  textContent: string;
  contentHash: string;
  screenshotUrl?: string;
  httpStatus: number;
  responseTime: number;
  changed: boolean;
  changePercentage?: number;
  importanceScore?: number;
  summary?: string;
  errorMessage?: string;
  createdAt: Date;
}

export interface Alert {
  id: string;
  monitorId: string;
  snapshotId: string;
  userId: string;
  type: AlertType;
  title: string;
  summary?: string;
  channels: AlertChannel[];
  deliveredAt?: Date;
  readAt?: Date;
  createdAt: Date;
}

export interface JWTPayload {
  userId: string;
  email: string;
  plan: UserPlan;
}

export interface CreateMonitorInput {
  url: string;
  name?: string;
  frequency: MonitorFrequency;
  elementSelector?: string;
  ignoreRules?: IgnoreRule[];
  keywordRules?: KeywordRule[];
}

export interface UpdateMonitorInput {
  name?: string;
  frequency?: MonitorFrequency;
  status?: MonitorStatus;
  elementSelector?: string;
  ignoreRules?: IgnoreRule[];
  keywordRules?: KeywordRule[];
}
