export type EndpointMethod = "GET" | "POST";

export type EndpointSpec = {
  id: string;
  group: string;
  path: string;
  method: EndpointMethod;
  bodyTemplate?: string;
  note?: string;
  requiredContext?: string[];
  destructive?: boolean;
};

const ENDPOINT_PATHS = [
  "/sign-in/social",
  "/sign-in/email",
  "/sign-in/username",
  "/sign-up/email",
  "/get-session",
  "/sign-out",
  "/forget-password",
  "/reset-password",
  "/verify-email",
  "/send-verification-email",
  "/change-email",
  "/change-email/verify",
  "/change-password",
  "/set-password",
  "/update-user",
  "/delete-user",
  "/delete-user/verify",
  "/delete-user/callback",
  "/email-list",
  "/email/list",
  "/list-sessions",
  "/revoke-session",
  "/revoke-sessions",
  "/revoke-other-sessions",
  "/link-social",
  "/list-accounts",
  "/unlink-account",
  "/refresh-token",
  "/get-access-token",
  "/two-factor/get-totp-uri",
  "/two-factor/verify-totp",
  "/two-factor/send-otp",
  "/two-factor/verify-otp",
  "/two-factor/verify-backup-code",
  "/two-factor/generate-backup-codes",
  "/two-factor/enable",
  "/two-factor/disable",
  "/passkey/generate-register-options",
  "/passkey/generate-authenticate-options",
  "/passkey/verify-registration",
  "/passkey/verify-authentication",
  "/passkey/list-user-passkeys",
  "/passkey/delete-passkey",
  "/passkey/update-passkey",
  "/.well-known/webauthn",
  "/admin/set-role",
  "/admin/list-users",
  "/admin/list-user-sessions",
  "/admin/create-user",
  "/admin/unban-user",
  "/admin/ban-user",
  "/admin/impersonate-user",
  "/admin/stop-impersonating",
  "/admin/revoke-user-session",
  "/admin/revoke-user-sessions",
  "/admin/remove-user",
  "/admin/set-user-password",
  "/admin/has-permission",
  "/admin/api-key/create",
  "/admin/athena-client/create",
  "/admin/athena-client/list",
  "/admin/oauth-client/create",
  "/admin/oauth-client/list",
  "/admin/audit-log/list",
  "/admin/email/get",
  "/admin/email/create",
  "/admin/email/update",
  "/admin/email/delete",
  "/admin/email-failure/list",
  "/admin/email-failure/get",
  "/admin/email-failure/create",
  "/admin/email-failure/update",
  "/admin/email-failure/delete",
  "/admin/email-template/get",
  "/admin/email-template/create",
  "/admin/email-template/delete",
  "/admin/email-template/list",
  "/admin/email-template/update",
  "/admin/email/list",
  "/api-key/create",
  "/api-key/get",
  "/api-key/update",
  "/api-key/delete",
  "/api-key/list",
  "/api-key/verify",
  "/api-key/delete-all-expired-api-keys",
  "/organization/create",
  "/organization/check-slug",
  "/organization/list",
  "/organization/set-active",
  "/organization/get-full-organization",
  "/organization/update",
  "/organization/delete",
  "/organization/invite-member",
  "/organization/accept-invitation",
  "/organization/cancel-invitation",
  "/organization/reject-invitation",
  "/organization/get-invitation",
  "/organization/list-invitations",
  "/organization/list-user-invitations",
  "/organization/list-members",
  "/organization/remove-member",
  "/organization/update-member-role",
  "/organization/get-active-member",
  "/organization/leave",
  "/organization/has-permission",
  "/callback/{{provider}}",
  "/health",
  "/ok",
  "/error",
  "/reset-password/{{resetToken}}",
] as const;

const GET_ENDPOINTS = new Set<string>([
  "/get-session",
  "/verify-email",
  "/change-email/verify",
  "/delete-user/verify",
  "/email-list",
  "/email/list",
  "/delete-user/callback",
  "/list-sessions",
  "/list-accounts",
  "/passkey/generate-register-options",
  "/passkey/list-user-passkeys",
  "/.well-known/webauthn",
  "/admin/list-users",
  "/admin/athena-client/list",
  "/admin/oauth-client/list",
  "/admin/audit-log/list",
  "/admin/email/get",
  "/admin/email-failure/list",
  "/admin/email-failure/get",
  "/admin/email-template/get",
  "/admin/email-template/list",
  "/admin/email/list",
  "/api-key/get",
  "/api-key/list",
  "/organization/get-full-organization",
  "/organization/list",
  "/organization/get-invitation",
  "/organization/list-invitations",
  "/organization/list-user-invitations",
  "/organization/list-members",
  "/organization/get-active-member",
  "/callback/{{provider}}",
  "/health",
  "/ok",
  "/error",
  "/reset-password/{{resetToken}}",
]);

const DESTRUCTIVE_HINTS = ["delete", "remove", "revoke", "ban", "unlink", "impersonate", "disable", "leave"];

const OVERRIDES: Record<string, Partial<EndpointSpec>> = {
  "/sign-in/social": {
    bodyTemplate: '{\n  "provider": "{{provider}}",\n  "callbackURL": "{{callbackUrl}}"\n}',
    requiredContext: ["provider", "callbackUrl"],
  },
  "/sign-in/email": {
    bodyTemplate: '{\n  "email": "{{email}}",\n  "password": "{{password}}",\n  "rememberMe": true\n}',
    requiredContext: ["email", "password"],
  },
  "/sign-in/username": {
    bodyTemplate: '{\n  "username": "{{username}}",\n  "password": "{{password}}"\n}',
    requiredContext: ["username", "password"],
  },
  "/sign-up/email": {
    bodyTemplate: '{\n  "name": "{{name}}",\n  "email": "{{email}}",\n  "password": "{{password}}",\n  "callbackURL": "{{callbackUrl}}"\n}',
    requiredContext: ["name", "email", "password"],
  },
  "/forget-password": {
    bodyTemplate: '{\n  "email": "{{email}}",\n  "redirectTo": "{{callbackUrl}}"\n}',
    requiredContext: ["email", "callbackUrl"],
  },
  "/reset-password": {
    bodyTemplate: '{\n  "token": "{{token}}",\n  "newPassword": "{{newPassword}}"\n}',
    requiredContext: ["token", "newPassword"],
  },
  "/verify-email": {
    path: "/verify-email?token={{token}}&callbackURL={{callbackUrl}}",
    requiredContext: ["token"],
  },
  "/change-email": {
    bodyTemplate: '{\n  "newEmail": "{{email}}",\n  "callbackURL": "{{callbackUrl}}"\n}',
    requiredContext: ["email"],
  },
  "/change-email/verify": {
    path: "/change-email/verify?token={{token}}",
    requiredContext: ["token"],
  },
  "/change-password": {
    bodyTemplate: '{\n  "currentPassword": "{{currentPassword}}",\n  "newPassword": "{{newPassword}}",\n  "revokeOtherSessions": false\n}',
    requiredContext: ["currentPassword", "newPassword"],
  },
  "/set-password": {
    bodyTemplate: '{\n  "newPassword": "{{newPassword}}"\n}',
    requiredContext: ["newPassword"],
  },
  "/update-user": {
    bodyTemplate: '{\n  "name": "{{name}}",\n  "image": "{{imageUrl}}"\n}',
  },
  "/delete-user": {
    bodyTemplate: '{\n  "password": "{{currentPassword}}"\n}',
    requiredContext: ["currentPassword"],
    destructive: true,
  },
  "/delete-user/verify": {
    path: "/delete-user/verify?token={{token}}",
    requiredContext: ["token"],
  },
  "/delete-user/callback": {
    path: "/delete-user/callback?token={{token}}&callbackURL={{callbackUrl}}",
    requiredContext: ["token"],
    destructive: true,
  },
  "/email-list": {
    path: "/email-list?limit={{limit}}&offset={{offset}}",
  },
  "/email/list": {
    path: "/email/list?limit={{limit}}&offset={{offset}}",
  },
  "/revoke-session": {
    bodyTemplate: '{\n  "token": "{{sessionToken}}"\n}',
    requiredContext: ["sessionToken"],
    destructive: true,
  },
  "/revoke-sessions": {
    bodyTemplate: "{}",
    destructive: true,
  },
  "/revoke-other-sessions": {
    bodyTemplate: "{}",
    destructive: true,
  },
  "/link-social": {
    bodyTemplate: '{\n  "provider": "{{provider}}",\n  "callbackURL": "{{callbackUrl}}"\n}',
    requiredContext: ["provider", "callbackUrl"],
  },
  "/unlink-account": {
    bodyTemplate: '{\n  "providerId": "{{providerId}}",\n  "accountId": "{{accountId}}"\n}',
    requiredContext: ["providerId", "accountId"],
    destructive: true,
  },
  "/refresh-token": {
    bodyTemplate: '{\n  "providerId": "{{providerId}}",\n  "accountId": "{{accountId}}",\n  "userId": "{{userId}}"\n}',
    requiredContext: ["providerId", "accountId", "userId"],
  },
  "/get-access-token": {
    bodyTemplate: '{\n  "providerId": "{{providerId}}",\n  "accountId": "{{accountId}}",\n  "userId": "{{userId}}"\n}',
    requiredContext: ["providerId", "accountId", "userId"],
  },
  "/two-factor/get-totp-uri": {
    bodyTemplate: '{\n  "password": "{{currentPassword}}"\n}',
    requiredContext: ["currentPassword"],
  },
  "/two-factor/verify-totp": {
    bodyTemplate: '{\n  "code": "{{code}}"\n}',
    requiredContext: ["code"],
  },
  "/two-factor/send-otp": {
    bodyTemplate: "{}",
  },
  "/two-factor/verify-otp": {
    bodyTemplate: '{\n  "code": "{{code}}"\n}',
    requiredContext: ["code"],
  },
  "/two-factor/verify-backup-code": {
    bodyTemplate: '{\n  "code": "{{backupCode}}"\n}',
    requiredContext: ["backupCode"],
  },
  "/two-factor/generate-backup-codes": {
    bodyTemplate: '{\n  "password": "{{currentPassword}}"\n}',
    requiredContext: ["currentPassword"],
  },
  "/two-factor/enable": {
    bodyTemplate: '{\n  "password": "{{currentPassword}}",\n  "code": "{{code}}"\n}',
    requiredContext: ["currentPassword", "code"],
  },
  "/two-factor/disable": {
    bodyTemplate: '{\n  "password": "{{currentPassword}}"\n}',
    requiredContext: ["currentPassword"],
    destructive: true,
  },
  "/passkey/generate-register-options": {
    path: "/passkey/generate-register-options?authenticatorAttachment={{authenticatorAttachment}}",
    requiredContext: ["authenticatorAttachment"],
  },
  "/passkey/generate-authenticate-options": {
    bodyTemplate: "{}",
  },
  "/passkey/verify-registration": {
    bodyTemplate: '{\n  "response": {{passkeyResponse}},\n  "name": "{{passkeyName}}"\n}',
    requiredContext: ["passkeyResponse"],
  },
  "/passkey/verify-authentication": {
    bodyTemplate: '{\n  "response": {{passkeyResponse}}\n}',
    requiredContext: ["passkeyResponse"],
  },
  "/passkey/delete-passkey": {
    bodyTemplate: '{\n  "id": "{{passkeyId}}"\n}',
    requiredContext: ["passkeyId"],
    destructive: true,
  },
  "/passkey/update-passkey": {
    bodyTemplate: '{\n  "id": "{{passkeyId}}",\n  "name": "{{passkeyName}}"\n}',
    requiredContext: ["passkeyId", "passkeyName"],
  },
  "/admin/set-role": {
    bodyTemplate: '{\n  "userId": "{{userId}}",\n  "role": "{{role}}"\n}',
    requiredContext: ["userId", "role"],
    destructive: true,
  },
  "/admin/list-users": {
    path: "/admin/list-users?limit={{limit}}&offset={{offset}}",
  },
  "/admin/list-user-sessions": {
    bodyTemplate: '{\n  "userId": "{{userId}}"\n}',
    requiredContext: ["userId"],
  },
  "/admin/create-user": {
    bodyTemplate: '{\n  "email": "{{email}}",\n  "name": "{{name}}",\n  "password": "{{password}}",\n  "role": "{{role}}"\n}',
    requiredContext: ["email", "password"],
  },
  "/admin/unban-user": {
    bodyTemplate: '{\n  "userId": "{{userId}}"\n}',
    requiredContext: ["userId"],
    destructive: true,
  },
  "/admin/ban-user": {
    bodyTemplate: '{\n  "userId": "{{userId}}",\n  "reason": "{{banReason}}"\n}',
    requiredContext: ["userId"],
    destructive: true,
  },
  "/admin/impersonate-user": {
    bodyTemplate: '{\n  "userId": "{{userId}}"\n}',
    requiredContext: ["userId"],
    destructive: true,
  },
  "/admin/stop-impersonating": {
    bodyTemplate: "{}",
    destructive: true,
  },
  "/admin/revoke-user-session": {
    bodyTemplate: '{\n  "userId": "{{userId}}",\n  "sessionToken": "{{sessionToken}}"\n}',
    requiredContext: ["userId", "sessionToken"],
    destructive: true,
  },
  "/admin/revoke-user-sessions": {
    bodyTemplate: '{\n  "userId": "{{userId}}"\n}',
    requiredContext: ["userId"],
    destructive: true,
  },
  "/admin/remove-user": {
    bodyTemplate: '{\n  "userId": "{{userId}}"\n}',
    requiredContext: ["userId"],
    destructive: true,
  },
  "/admin/set-user-password": {
    bodyTemplate: '{\n  "userId": "{{userId}}",\n  "newPassword": "{{newPassword}}"\n}',
    requiredContext: ["userId", "newPassword"],
    destructive: true,
  },
  "/admin/has-permission": {
    bodyTemplate: '{\n  "userId": "{{userId}}",\n  "permissions": {{permissionsJson}}\n}',
    requiredContext: ["userId", "permissionsJson"],
  },
  "/admin/api-key/create": {
    bodyTemplate: '{\n  "name": "{{apiKeyName}}",\n  "expiresIn": "{{apiKeyExpiresIn}}"\n}',
  },
  "/admin/athena-client/create": {
    bodyTemplate: '{\n  "name": "{{athenaClientName}}",\n  "baseUrl": "{{athenaClientBaseUrl}}",\n  "apiKey": "{{athenaClientApiKey}}"\n}',
  },
  "/admin/oauth-client/create": {
    bodyTemplate:
      '{\n  "clientName": "{{oauthClientName}}",\n  "provider": "{{provider}}",\n  "redirectUris": ["{{callbackUrl}}"],\n  "grantType": "authorization_code",\n  "responseType": "code",\n  "tokenAuthenticationMethod": "none"\n}',
    requiredContext: ["oauthClientName", "provider", "callbackUrl"],
  },
  "/admin/email/get": {
    path: "/admin/email/get?id={{emailId}}",
    requiredContext: ["emailId"],
  },
  "/admin/email/create": {
    bodyTemplate: '{\n  "recipientEmail": "{{recipientEmail}}",\n  "subject": "{{subject}}",\n  "fromAddress": "{{fromAddress}}",\n  "provider": "{{emailProvider}}"\n}',
    requiredContext: ["recipientEmail", "subject", "fromAddress"],
  },
  "/admin/email/update": {
    bodyTemplate: '{\n  "id": "{{emailId}}",\n  "subject": "{{subject}}"\n}',
    requiredContext: ["emailId"],
    destructive: true,
  },
  "/admin/email/delete": {
    bodyTemplate: '{\n  "id": "{{emailId}}"\n}',
    requiredContext: ["emailId"],
    destructive: true,
  },
  "/admin/email-failure/list": {
    path: "/admin/email-failure/list?limit={{limit}}&offset={{offset}}",
  },
  "/admin/email-failure/get": {
    path: "/admin/email-failure/get?id={{emailFailureId}}",
    requiredContext: ["emailFailureId"],
  },
  "/admin/email-failure/create": {
    bodyTemplate: '{\n  "emailId": "{{emailId}}",\n  "error": "{{failureReason}}"\n}',
  },
  "/admin/email-failure/update": {
    bodyTemplate: '{\n  "id": "{{emailFailureId}}",\n  "error": "{{failureReason}}"\n}',
    requiredContext: ["emailFailureId"],
    destructive: true,
  },
  "/admin/email-failure/delete": {
    bodyTemplate: '{\n  "id": "{{emailFailureId}}"\n}',
    requiredContext: ["emailFailureId"],
    destructive: true,
  },
  "/admin/email-template/get": {
    path: "/admin/email-template/get?id={{emailTemplateId}}",
    requiredContext: ["emailTemplateId"],
  },
  "/admin/email-template/create": {
    bodyTemplate: '{\n  "templateKey": "{{templateKey}}",\n  "subjectTemplate": "{{subjectTemplate}}"\n}',
    requiredContext: ["templateKey", "subjectTemplate"],
  },
  "/admin/email-template/delete": {
    bodyTemplate: '{\n  "id": "{{emailTemplateId}}"\n}',
    requiredContext: ["emailTemplateId"],
    destructive: true,
  },
  "/admin/email-template/list": {
    path: "/admin/email-template/list?limit={{limit}}&offset={{offset}}",
  },
  "/admin/email-template/update": {
    bodyTemplate: '{\n  "id": "{{emailTemplateId}}",\n  "subjectTemplate": "{{subjectTemplate}}"\n}',
    requiredContext: ["emailTemplateId"],
    destructive: true,
  },
  "/admin/email/list": {
    path: "/admin/email/list?limit={{limit}}&offset={{offset}}",
  },
  "/api-key/create": {
    bodyTemplate: '{\n  "name": "{{apiKeyName}}",\n  "expiresIn": "{{apiKeyExpiresIn}}",\n  "remaining": "{{apiKeyRemaining}}"\n}',
  },
  "/api-key/get": {
    path: "/api-key/get?id={{keyId}}",
  },
  "/api-key/update": {
    bodyTemplate: '{\n  "keyId": "{{keyId}}",\n  "name": "{{apiKeyName}}",\n  "expiresIn": "{{apiKeyExpiresIn}}",\n  "permissions": "{{apiKeyPermissions}}"\n}',
    requiredContext: ["keyId"],
    destructive: true,
  },
  "/api-key/delete": {
    bodyTemplate: '{\n  "keyId": "{{keyId}}"\n}',
    requiredContext: ["keyId"],
    destructive: true,
  },
  "/api-key/verify": {
    bodyTemplate: '{\n  "key": "{{apiKeyValue}}"\n}',
    requiredContext: ["apiKeyValue"],
  },
  "/api-key/delete-all-expired-api-keys": {
    bodyTemplate: "{}",
    destructive: true,
  },
  "/organization/create": {
    bodyTemplate: '{\n  "name": "{{organizationName}}",\n  "slug": "{{organizationSlug}}"\n}',
    requiredContext: ["organizationName", "organizationSlug"],
  },
  "/organization/check-slug": {
    bodyTemplate: '{\n  "slug": "{{organizationSlug}}"\n}',
    requiredContext: ["organizationSlug"],
  },
  "/organization/set-active": {
    bodyTemplate: '{\n  "organizationId": "{{organizationId}}"\n}',
    requiredContext: ["organizationId"],
  },
  "/organization/get-full-organization": {
    path: "/organization/get-full-organization?organizationId={{organizationId}}",
    requiredContext: ["organizationId"],
  },
  "/organization/update": {
    bodyTemplate: '{\n  "organizationId": "{{organizationId}}",\n  "data": {\n    "name": "{{organizationName}}",\n    "slug": "{{organizationSlug}}"\n  }\n}',
    requiredContext: ["organizationId"],
    destructive: true,
  },
  "/organization/delete": {
    bodyTemplate: '{\n  "organizationId": "{{organizationId}}"\n}',
    requiredContext: ["organizationId"],
    destructive: true,
  },
  "/organization/invite-member": {
    bodyTemplate: '{\n  "organizationId": "{{organizationId}}",\n  "email": "{{inviteEmail}}",\n  "role": "{{inviteRole}}",\n  "callbackURL": "{{callbackUrl}}"\n}',
    requiredContext: ["organizationId", "inviteEmail", "inviteRole", "callbackUrl"],
  },
  "/organization/accept-invitation": {
    bodyTemplate: '{\n  "invitationId": "{{invitationId}}"\n}',
    requiredContext: ["invitationId"],
  },
  "/organization/cancel-invitation": {
    bodyTemplate: '{\n  "invitationId": "{{invitationId}}"\n}',
    requiredContext: ["invitationId"],
    destructive: true,
  },
  "/organization/reject-invitation": {
    bodyTemplate: '{\n  "invitationId": "{{invitationId}}"\n}',
    requiredContext: ["invitationId"],
    destructive: true,
  },
  "/organization/get-invitation": {
    path: "/organization/get-invitation?id={{invitationId}}",
    requiredContext: ["invitationId"],
  },
  "/organization/list-invitations": {
    path: "/organization/list-invitations?organizationId={{organizationId}}",
    requiredContext: ["organizationId"],
  },
  "/organization/list-user-invitations": {
    path: "/organization/list-user-invitations?limit={{limit}}&offset={{offset}}",
  },
  "/organization/list-members": {
    path: "/organization/list-members?organizationId={{organizationId}}&limit={{limit}}&offset={{offset}}",
    requiredContext: ["organizationId"],
  },
  "/organization/remove-member": {
    bodyTemplate: '{\n  "memberIdOrEmail": "{{memberIdOrEmail}}",\n  "organizationId": "{{organizationId}}"\n}',
    requiredContext: ["memberIdOrEmail", "organizationId"],
    destructive: true,
  },
  "/organization/update-member-role": {
    bodyTemplate: '{\n  "memberId": "{{memberId}}",\n  "role": "{{inviteRole}}",\n  "organizationId": "{{organizationId}}"\n}',
    requiredContext: ["memberId", "inviteRole", "organizationId"],
    destructive: true,
  },
  "/organization/get-active-member": {
    path: "/organization/get-active-member?organizationId={{organizationId}}",
    requiredContext: ["organizationId"],
  },
  "/organization/leave": {
    bodyTemplate: '{\n  "organizationId": "{{organizationId}}"\n}',
    requiredContext: ["organizationId"],
    destructive: true,
  },
  "/organization/has-permission": {
    bodyTemplate: '{\n  "organizationId": "{{organizationId}}",\n  "permissions": {{permissionsJson}}\n}',
    requiredContext: ["organizationId", "permissionsJson"],
  },
  "/callback/{{provider}}": {
    path: "/callback/{{provider}}?code={{oauthCode}}&state={{oauthState}}",
    requiredContext: ["provider", "oauthCode", "oauthState"],
  },
  "/reset-password/{{resetToken}}": {
    path: "/reset-password/{{resetToken}}?callbackURL={{callbackUrl}}",
    requiredContext: ["resetToken"],
  },
};

function inferGroup(path: string): string {
  if (path.startsWith("/organization/")) return "Organization";
  if (path.startsWith("/api-key/")) return "API Keys";
  if (path.startsWith("/admin/email")) return "Admin Email";
  if (path.startsWith("/admin/list-users") || path.startsWith("/admin/list-user-sessions") || path.startsWith("/admin/create-user") || path.startsWith("/admin/unban-user") || path.startsWith("/admin/ban-user") || path.startsWith("/admin/impersonate-user") || path.startsWith("/admin/stop-impersonating") || path.startsWith("/admin/revoke-user-session") || path.startsWith("/admin/revoke-user-sessions") || path.startsWith("/admin/remove-user") || path.startsWith("/admin/set-user-password") || path.startsWith("/admin/set-role") || path.startsWith("/admin/has-permission")) {
    return "Admin Users";
  }
  if (path.startsWith("/admin/")) return "Admin Platform";
  if (path.startsWith("/passkey/") || path === "/.well-known/webauthn") return "Passkey";
  if (path.startsWith("/two-factor/")) return "Two-Factor";
  if (path.startsWith("/revoke-") || path === "/list-sessions") return "Session";
  if (path.startsWith("/sign-in") || path.startsWith("/sign-up") || path.startsWith("/forget-password") || path.startsWith("/reset-password") || path.startsWith("/verify-email") || path.startsWith("/change-email") || path.startsWith("/change-password") || path.startsWith("/set-password") || path.startsWith("/update-user") || path.startsWith("/delete-user") || path.startsWith("/email")) {
    return "Auth Core";
  }
  if (path.startsWith("/link-social") || path.startsWith("/list-accounts") || path.startsWith("/unlink-account") || path.startsWith("/refresh-token") || path.startsWith("/get-access-token") || path.startsWith("/callback/")) {
    return "Social & Account";
  }
  if (path === "/health" || path === "/ok" || path === "/error") return "Diagnostics";
  return "Auth Core";
}

function inferMethod(path: string): EndpointMethod {
  return GET_ENDPOINTS.has(path) ? "GET" : "POST";
}

function inferDestructive(path: string): boolean {
  return DESTRUCTIVE_HINTS.some((hint) => path.includes(hint));
}

function pathToId(path: string): string {
  return path
    .replace(/\{\{([^}]+)\}\}/g, "$1")
    .replace(/[^a-zA-Z0-9]+/g, "-")
    .replace(/^-+|-+$/g, "")
    .toLowerCase();
}

export function getAuthEndpointSpecs(): EndpointSpec[] {
  return ENDPOINT_PATHS.map((path) => {
    const override = OVERRIDES[path] ?? {};
    const method = override.method ?? inferMethod(path);
    const bodyTemplate =
      override.bodyTemplate ?? (method === "POST" ? "{}" : undefined);

    return {
      id: override.id ?? pathToId(path),
      group: override.group ?? inferGroup(path),
      path: override.path ?? path,
      method,
      bodyTemplate,
      note: override.note,
      requiredContext: override.requiredContext,
      destructive: override.destructive ?? inferDestructive(path),
    };
  });
}

export function getEndpointGroupOrder(specs: EndpointSpec[]): string[] {
  return Array.from(new Set(specs.map((spec) => spec.group)));
}
