import type { Response, CookieOptions } from "express";

/**
 * Custom setSecureCookie function signature.
 * This is added by our security middleware.
 */
export type SetSecureCookieFn = (name: string, value: string, options?: CookieOptions) => void;

/**
 * Get setSecureCookie function from response if available.
 * Returns null if the custom helper is not present.
 */
export function getSecureCookie(res: Response): SetSecureCookieFn | null {
  const maybeSecure = res as Response & { setSecureCookie?: unknown };
  if (typeof maybeSecure.setSecureCookie === "function") {
    return maybeSecure.setSecureCookie.bind(res) as SetSecureCookieFn;
  }
  return null;
}
