export type UserRole = 'subscriber' | 'author' | 'admin';
export type UserStatus = 'active' | 'banned' | 'pending';

export interface Env {
  Bindings: {
    DB: D1Database;
    R2: R2Bucket;
    KV: KVNamespace;
    ASSETS: Fetcher;
    SITE_URL: string;
    COOKIE_NAME?: string;
    SESSION_TTL_DAYS?: string;
    SESSION_SECRET?: string;
    TENCENT_MAP_KEY?: string;
    ADMIN_BOOTSTRAP_TOKEN?: string;
  };
  Variables: {
    requestId: string;
    currentUser: CurrentUser | null;
    csrfToken: string;
  };
}

export interface CurrentUser {
  id: string;
  username: string;
  email: string;
  displayName: string;
  avatarKey: string | null;
  bio: string;
  url: string;
  role: UserRole;
  status: UserStatus;
}

export interface SiteSettings {
  site_name: string;
  site_description: string;
  site_avatar_key: string;
  top_image_key: string;
  top_video_key: string;
  avatar_link: string;
  avatar_mirror: string;
  tencent_map_key: string;
  beian_info: string;
  list_collapse: boolean;
  custom_css: string;
  custom_js: string;
  analytics_code: string;
  allow_register: boolean;
  default_role: UserRole;
  comment_mode: 'everyone' | 'registered' | 'closed';
  comment_review: boolean;
  upload_max_image_mb: number;
  upload_max_video_mb: number;
  cdn_base_url: string;
}

export interface ApiEnvelope<T = unknown> {
  success: boolean;
  data?: T;
  message?: string;
  code?: string;
}
