import type { UserClaims, OpenAPIServer } from '@redocly/theme/core/types';

export type SecurityDetails = {
  password?: string;
  username?: string;
  token?: {
    token_type?: string;
    access_token: string;
  };
  client_id?: string;
  client_secret?: string;
  scopes?: string[];
};

export type ConfigureRequestValues = {
  headers?: Record<string, string>;
  /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
  body?: Record<string, any>;
  query?: Record<string, string>;
  path?: Record<string, string>;
  cookie?: Record<string, string>;
  security?: Record<string, SecurityDetails>;
  envVariables?: Record<string, string>;
  serverVariables?: Record<string, string>;
};

export type ConfigureServerRequestValues = {
  [serverUrl: string]: ConfigureRequestValues;
};

type Configure = {
  requestValues?: ConfigureRequestValues | ConfigureServerRequestValues;
};

type ContextProps = {
  userClaims?: UserClaims;
  operation: {
    name: string;
    path: string;
    operationId?: string;
    href?: string;
    method: string;
  };
  servers: OpenAPIServer[];
};

export function configure(_context: ContextProps): Configure {
  // const exampleDefaultRequestValues: ConfigureRequestValues = {
  //   body: {
  //     name: 'Default Product'
  //   },
  //   security: {
  //     default: {
  //       username: 'default_api_user',
  //       password: 'secureP@ssword123'
  //     },
  //   },
  //   envVariables: {
  //     customLocation: 'default'
  //   },
  // };

  // const exampleDevRequestValues: ConfigureRequestValues = {
  //   body: {
  //     name: 'Development Product'
  //   },
  //   security: {
  //     default: {
  //       username: 'dev_api_user',
  //       password: 'Dev@P!T3st'
  //     },
  //   },
  //   envVariables: {
  //     customLocation: 'dev'
  //   },
  // };

  // const exampleProdRequestValues: ConfigureRequestValues = {
  //   body: {
  //     name: 'Production Product'
  //   },
  //   security: {
  //     default: {
  //       username: 'prod_api_user',
  //       password: 'Pr0d@P!S3cur3'
  //     },
  //   },
  //   envVariables: {
  //     customLocation: 'prod'
  //   },
  //   serverVariables: {
  //     version: 'v1',
  //   },
  // };

  // const { servers } = _context;
  //   const serverRequestValues: ConfigureServerRequestValues = {};

  // for (const server of servers) {
  //   if (server.url === 'https://dev.api.fake-museum-example.com') {
  //     serverRequestValues[server.url] = exampleDevRequestValues;
  //   } else if (server.url === 'https://api.fake-museum-example.com/{version}') {
  //     serverRequestValues[server.url] = exampleProdRequestValues;
  //   } else {
  //     serverRequestValues[server.url] = exampleDefaultRequestValues;
  //   }
  // }

  // Uncomment the following to use default request values for all servers
  // return {
  //   requestValues: exampleDefaultRequestValues,
  // } satisfies Configure;

  // Uncomment the following to use server-specific request values
  // return {
  //   requestValues: serverRequestValues
  // } satisfies Configure;
  return {} satisfies Configure;
}
