export interface ApiResponse<T> {
  code: number;
  message: string;
  data: T;
}

export interface UserProfile {
  id: number;
  phone: string;
  name: string;
  nickname?: string | null;
  dailyLimit: number;
  todayUsed: number;
  status: number;
  entitlement?: UserEntitlementSummary | null;
}

export interface UserEntitlementSummary {
  planId: number | null;
  name: string;
  planType: string;
  description?: string | null;
  validityDays?: number | null;
  monthlyTopicLimit: number | null;
  monthlyTopicUsed: number;
  monthlyTopicRemaining: number | null;
  enableGrowthProfile: boolean;
  enablePeriodicReports: boolean;
  allowHelpCard: boolean;
  allowShareDraft: boolean;
  deductQuota: boolean;
  effectiveAt?: string | null;
  expiredAt?: string | null;
  source: string;
  lifecycleStatus: "active" | "long_term" | "expiring_7" | "expiring_30" | "expired_fallback" | "default" | "legacy" | string;
  daysUntilExpiry?: number | null;
  previousPlanName?: string | null;
  previousExpiredAt?: string | null;
}

export interface TopicSummary {
  id: number;
  topicSessionId: number;
  schemaVersion: number;
  summary: string;
  currentFocus?: string | null;
  nextObservation?: string | null;
  status: "pending" | "running" | "success" | "fallback" | "failed" | string;
  errorMessage?: string | null;
  attemptCount: number;
  maxAttempts: number;
  nextRunAt?: string | null;
  lastStartedAt?: string | null;
  finishedAt?: string | null;
  generatedAt: string;
}

export interface PracticeReview {
  id: number;
  userId: number;
  schemaVersion: number;
  reviewText: string;
  currentFocus?: string | null;
  sourceSummaryIds: number[];
  updatedAt: string;
}

export interface PracticeReviewResult {
  profile: PracticeReview | null;
  recentSummaries: TopicSummary[];
}

export interface PeriodicReport {
  id: number;
  schemaVersion: number;
  reportType: "weekly" | "monthly" | "stage" | string;
  reportTypeLabel: string;
  periodStart: string;
  periodEnd: string;
  title: string;
  content: string;
  status: "success" | "failed" | "empty" | string;
  generatedAt: string;
}

export interface FinishTopicResult {
  topic: Record<string, unknown>;
  summary: TopicSummary & Record<string, unknown>;
  profile: PracticeReview | null;
  growthProfileEnabled: boolean;
  settlementStatus: string;
}

export interface TeacherHelpCard {
  id: number;
  userId: number;
  topicSessionId: number;
  summaryId?: number | null;
  content: string;
  source: string;
  copied: boolean;
  copiedAt?: string | null;
  createdAt: string;
}

export interface ShareDraft {
  id: number;
  userId: number;
  topicSessionId: number;
  summaryId?: number | null;
  content: string;
  source: string;
  copied: boolean;
  copiedAt?: string | null;
  createdAt: string;
}

export interface LoginResult {
  token: string;
  expiredAt: string;
  user: UserProfile;
  returnUrl?: string | null;
}

export interface CaptchaResult {
  captchaId: string;
  imageBase64: string;
  expiresInSeconds: number;
}

export interface VoiceInputConfig {
  enabled: boolean;
  maxDurationSeconds: number;
}

export interface VoiceTranscriptionResult {
  text: string;
  durationSeconds: number;
}

export interface ChatSession {
  id: number;
  title: string;
  messageCount: number;
  updatedAt: string;
}

export interface ChatMessage {
  id: number;
  role: "user" | "assistant";
  content: string;
  message_status: string;
  created_at: string;
}
