export type User = {
  id: string;
  email: string;
  role: "admin" | "user";
  active?: boolean;
  createdAt?: string;
  notificationSetting?: NotificationSettings | null;
  botAccesses?: UserBotAccess[];
};

export type SubscriptionStatus = "active" | "expired" | "canceled";

export type Bot = {
  id: string;
  key: string;
  name: string;
  sourceUrl: string;
  active: boolean;
};

export type UserBotAccess = {
  id: string;
  grantedAt: string;
  status: SubscriptionStatus;
  startsAt: string;
  expiresAt?: string | null;
  notes?: string | null;
  isActiveNow?: boolean;
  bot: Bot;
};

export type Signal = {
  id: string;
  eventId: string;
  sportType: string;
  leagueName: string;
  homeTeam: string;
  awayTeam: string;
  eventStartTime: string;
  marketType: string;
  selection: string;
  forecast?: string | null;
  lineValue: number | null;
  odds: number;
  signalTime: string;
  status: "pending" | "win" | "lose" | "void" | "manual_review" | "unpublished";
  sourceType: "manual" | "provider";
  comment?: string | null;
  published: boolean;
  rawPayload?: {
    botKey?: string;
    botName?: string;
    botUrl?: string;
    forecast?: string;
    forecastRaw?: string;
    forecastImageUrl?: string;
    forecastSource?: string;
    activeTab?: number | string;
    forecastInactive?: boolean;
  } | null;
};

export type PaginatedResponse<T> = {
  items: T[];
  pagination: {
    page: number;
    perPage: number;
    total: number;
    totalPages: number;
  };
  tabCounts?: {
    all: number;
    "1": number;
    "2": number;
  };
};

export type ActiveSignalCountByBot = {
  botId: string;
  botKey: string;
  botName: string;
  activeSignals: number;
};

export type NotificationSettings = {
  signalsPushEnabled: boolean;
  resultsPushEnabled: boolean;
};

export type SupportConversationStatus = "open" | "closed";

export type SupportMessage = {
  id: string;
  conversationId: string;
  body: string;
  createdAt: string;
  updatedAt: string;
  author: {
    id: string;
    email: string;
    role: "admin" | "user";
  };
};

export type SupportConversation = {
  id: string;
  status: SupportConversationStatus;
  createdAt: string;
  updatedAt: string;
  lastMessageAt: string;
  lastUserMessageAt?: string | null;
  lastAdminMessageAt?: string | null;
  unreadForAdmin: boolean;
  unreadForUser: boolean;
  user: {
    id: string;
    email: string;
    role: "admin" | "user";
    active?: boolean;
  };
  assignedAdmin?: {
    id: string;
    email: string;
    role: "admin" | "user";
  } | null;
  latestMessage?: SupportMessage | null;
  messages?: SupportMessage[];
};
