// API Response types
export interface ApiResponse<T = any> {
  success: boolean;
  message: string;
  data?: T;
}

// User types
export interface User {
  telegram_id: number;
  username: string;
  first_name: string;
  last_name: string;
  stars_balance: number;
  created_at: string;
  photo_url?: string;
}

// Quiz types
export interface Quiz {
  id: number;
  title: string;
  description: string;
  image_url: string;
  reward_stars: number;
  has_timer: boolean;
  timer_per_question: number;
  can_repeat: boolean;
  repeat_cooldown_hours: number;
  is_active: boolean;
  created_by: number;
  created_at: string;
  questions?: Question[];
}

export interface Question {
  id: number;
  quiz_id: number;
  text: string;
  type: 'single' | 'multiple';
  options: Option[];
  order_index: number;
}

export interface Option {
  id: number;
  text: string;
  is_correct: boolean;
}

export interface UserAnswer {
  question_id: number;
  option_ids: number[];
}

export interface SubmissionRequest {
  answers: UserAnswer[];
}

export interface SubmissionResponse {
  score: number;
  total_questions: number;
  stars_earned: number;
  correct_answers: number;
}

export interface CanRepeatResponse {
  can_repeat: boolean;
  next_available_at?: string;
}

// Reward types
export interface Reward {
  id: number;
  title: string;
  description?: string;
  image_url?: string;
  price_stars: number;
  delivery_type: 'physical' | 'digital';
  instructions?: string;
  stock: number;
  is_active: boolean;
  created_by?: number;
  created_at: string;
}

export interface Purchase {
  id: number;
  user_id: number;
  reward_id: number;
  stars_spent: number;
  purchased_at: string;
  status: 'pending' | 'delivered' | 'cancelled';
}

// Transaction types
export interface Transaction {
  amount: number;
  created_at: string;
  description: string;
  type: 'earned' | 'spent';
}

// QR types
export interface QRValidateRequest {
  payload: string;
}

export interface QRValidateResponse {
  type: 'reward' | 'quiz' | 'shop';
  value: string;
  message: string;
  data?: any;
}

// Admin types
export interface CreateOperatorRequest {
  telegram_id: number;
  name: string;
}

export interface GrantStarsRequest {
  user_id: number;
  amount: number;
  reason?: string;
}

export interface GenerateQRCodesRequest {
  type: 'reward' | 'quiz';
  value: string;
  count: number;
}

export interface GenerateQRCodesResponse {
  tokens: string[];
}

export interface Analytics {
  total_users: number;
  total_quizzes_completed: number;
  total_stars_earned: number;
  total_purchases: number;
  recent_activity: {
    date: string;
    quizzes_completed: number;
    qr_scans: number;
    purchases: number;
  }[];
  top_quizzes: {
    id: number;
    title: string;
    completions: number;
  }[];
  top_rewards: {
    id: number;
    title: string;
    purchases: number;
  }[];
}