// 运行时的log类型, 分为info, success, error
type LogType = {
  err: (v: string | Error) => void;
  info: (v: string) => void;
  success: (v: string) => void;
};

interface ContextData {
  query?: unknown;
  params?: unknown;
  res?: unknown;
}
interface HttpContext<T extends ContextData = ContextData> {
  readonly key: string; // context的key由api构造
  readonly method: HttpInstructMethod[];
  readonly proto: Record<string, unknown> | null;
  readonly reqHeaders: Record<string, unknown>;
  resHeaders: Record<string, unknown>;
  query: T['query'];
  params: T['params'];
  return?: {
    data: T['res']; // 返回对象
  };
}

type HttpInstructMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE';

type Plugin = {
  name: string;
  // 提供几个钩子用来定义函数，作为框架runtime的shim
  server?: {
    start: (...args: any[]) => Promise<void> | void;
  };
  log?: LogType;
  context?: (context: HttpContext) => HttpContext;
};

declare const useServer: () => Plugin;

export { useServer };
