export interface EndpointTypeEntry {
  request?: unknown
  response?: unknown
}

export type EndpointTypeMap = Record<string, EndpointTypeEntry>

export type NormalizePath<Path extends string> = Path extends ''
  ? '/'
  : Path extends `/${string}`
  ? Path
  : Path extends `${string}://${string}`
  ? Path
  : `/${Path}`

export type EndpointKey<Method extends string, Path extends string> = `${Uppercase<Method>} ${NormalizePath<Path>}`

export type EndpointResponse<
  Map extends EndpointTypeMap,
  Method extends string,
  Path extends string
> = EndpointKey<Method, Path> extends keyof Map
  ? Map[EndpointKey<Method, Path>] extends { response?: infer R }
    ? R
    : unknown
  : unknown

export type EndpointRequest<
  Map extends EndpointTypeMap,
  Method extends string,
  Path extends string
> = EndpointKey<Method, Path> extends keyof Map
  ? Map[EndpointKey<Method, Path>] extends { request?: infer R }
    ? R
    : unknown
  : unknown
