import { Request } from "express"

// Permissive Octokit type
export type AnyOctokit = any

// PR response type
export type PullRequestCreationResponse = any

// Subscription info attached by track-usage middleware
export interface SubscriptionInfo {
  userId: string
  tier: string
  used: number
  limit: number
}

// Extended Request with userId and organizationId
export interface AuthorizedUserReq extends Request {
  userId?: string
  organizationId?: string | null
  user?: {
    id: string
    email?: string
  }
  subscriptionInfo?: SubscriptionInfo
}

// PR database interface
export interface PullRequestDB {
  pull_request: {
    dependent_pr_url?: string
    review_suggestion_pr_url?: string
    [key: string]: any
  }
}

// Complete AsyncExpressApp interface
export interface AsyncExpressApp {
  post: ((path: string, handler: any) => AsyncExpressApp) &
    ((path: string, middleware: any, handler: any) => AsyncExpressApp) &
    ((path: string, ...handlers: any[]) => AsyncExpressApp)

  // Async methods
  postAsync: (path: string, handler: (req: any, res: any, next?: any) => Promise<any>) => void
  getAsync: (path: string, handler: (req: any, res: any, next?: any) => Promise<any>) => void

  // Standard Express methods
  use: (pathOrMiddleware: any, middleware?: any) => AsyncExpressApp
  get: (path: string, handler: (req: any, res: any, next?: any) => any) => AsyncExpressApp
  put: (path: string, handler: (req: any, res: any, next?: any) => any) => AsyncExpressApp
  delete: (path: string, handler: (req: any, res: any, next?: any) => any) => AsyncExpressApp
  patch: (path: string, handler: (req: any, res: any, next?: any) => any) => AsyncExpressApp
  listen: (port: number, callback?: () => void) => any
}
