use super::*;

pub(super) const HTTP_ROWS: &[NativeModSig] = &[
    // ========== node:http / node:https client (issue #769) ==========
    // `http.request(url_or_options, cb)` / `http.get(url_or_options, cb)`
    // and their `https.*` variants. Runtime impls live in
    // `crates/perry-stdlib/src/http.rs` and have been declared in the FFI
    // table for a while, but no `NativeModSig` entries existed — so user
    // code calling `http.request(...)` fell through to the unknown-method
    // path and got back `TAG_UNDEFINED`. Return is a `ClientRequest`
    // handle; the let-stmt arm in `crates/perry-hir/src/lower.rs` tags
    // the binding so `req.on/.end/.write/...` dispatch via the
    // class-filtered entries below.
    NativeModSig {
        module: "http",
        has_receiver: false,
        method: "request",
        class_filter: None,
        runtime: "js_http_request",
        args: &[NA_F64, NA_PTR],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "http",
        has_receiver: false,
        method: "get",
        class_filter: None,
        runtime: "js_http_get",
        args: &[NA_F64, NA_PTR],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "https",
        has_receiver: false,
        method: "request",
        class_filter: None,
        runtime: "js_https_request",
        args: &[NA_F64, NA_PTR],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "https",
        has_receiver: false,
        method: "get",
        class_filter: None,
        runtime: "js_https_get",
        args: &[NA_F64, NA_PTR],
        ret: NR_PTR,
    },
    // ClientRequest instance methods (`req.on/.end/.write/.setHeader/.setTimeout`).
    // Shared between `http` and `https` factories — both register the
    // returned binding under module `"http"` in the HIR class table.
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "on",
        class_filter: Some("ClientRequest"),
        runtime: "js_http_on",
        args: &[NA_STR, NA_PTR],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "end",
        class_filter: Some("ClientRequest"),
        runtime: "js_http_client_request_end",
        args: &[NA_F64],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "write",
        class_filter: Some("ClientRequest"),
        runtime: "js_http_client_request_write",
        args: &[NA_F64],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "setHeader",
        class_filter: Some("ClientRequest"),
        runtime: "js_http_set_header",
        args: &[NA_STR, NA_STR],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "setTimeout",
        class_filter: Some("ClientRequest"),
        runtime: "js_http_set_timeout",
        args: &[NA_F64],
        ret: NR_PTR,
    },
    // ========== node:http server (issue #577) ==========
    // Module-level: `import { createServer } from "node:http"; createServer(handler)`
    NativeModSig {
        module: "http",
        has_receiver: false,
        method: "createServer",
        class_filter: None,
        runtime: "js_node_http_create_server",
        args: &[NA_PTR],
        ret: NR_PTR,
    },
    // HttpServer instance methods (class_filter: HttpServer)
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "listen",
        class_filter: Some("HttpServer"),
        runtime: "js_node_http_server_listen",
        args: &[NA_F64, NA_PTR],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "close",
        class_filter: Some("HttpServer"),
        runtime: "js_node_http_server_close",
        args: &[NA_PTR],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "closeAllConnections",
        class_filter: Some("HttpServer"),
        runtime: "js_node_http_server_close_all_connections",
        args: &[],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "closeIdleConnections",
        class_filter: Some("HttpServer"),
        runtime: "js_node_http_server_close_idle_connections",
        args: &[],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "on",
        class_filter: Some("HttpServer"),
        runtime: "js_node_http_server_on",
        args: &[NA_STR, NA_PTR],
        ret: NR_F64,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "addListener",
        class_filter: Some("HttpServer"),
        runtime: "js_node_http_server_on",
        args: &[NA_STR, NA_PTR],
        ret: NR_F64,
    },
    // IncomingMessage instance methods
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "on",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_on",
        args: &[NA_STR, NA_PTR],
        ret: NR_F64,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "addListener",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_on",
        args: &[NA_STR, NA_PTR],
        ret: NR_F64,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "pause",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_pause",
        args: &[],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "resume",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_resume",
        args: &[],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "destroy",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_destroy",
        args: &[],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "read",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_read",
        args: &[],
        ret: NR_F64,
    },
    // ServerResponse instance methods
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "setHeader",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_set_header",
        args: &[NA_STR, NA_STR],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "getHeader",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_get_header",
        args: &[NA_STR],
        ret: NR_F64,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "removeHeader",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_remove_header",
        args: &[NA_STR],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "hasHeader",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_has_header",
        args: &[NA_STR],
        ret: NR_I32,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "writeHead",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_write_head",
        args: &[NA_F64, NA_STR, NA_STR],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "write",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_write",
        args: &[NA_F64],
        ret: NR_I32,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "end",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_end",
        args: &[NA_F64],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "flushHeaders",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_flush_headers",
        args: &[],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "writeContinue",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_write_continue",
        args: &[],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "writeProcessing",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_write_processing",
        args: &[],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "on",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_on",
        args: &[NA_STR, NA_PTR],
        ret: NR_F64,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "addListener",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_on",
        args: &[NA_STR, NA_PTR],
        ret: NR_F64,
    },
    // Method-call aliases for property-style accessors. Until the
    // HIR-level PropertyGet→__get_<name> rewrite lands (followup),
    // user code must use the method-call form: `req.method()` (calls
    // js_node_http_im_method) instead of `req.method` (property
    // read). Same shape as fastify's `request.method()` / `request.url()`.
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "method",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_method",
        args: &[],
        ret: NR_STR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "url",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_url",
        args: &[],
        ret: NR_STR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "httpVersion",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_http_version",
        args: &[],
        ret: NR_STR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "setStatus",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_set_status",
        args: &[NA_F64],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "getStatus",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_get_status",
        args: &[],
        ret: NR_F64,
    },
    // Property accessors as `__get_<name>` / `__set_<name>` synthetic methods
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_method",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_method",
        args: &[],
        ret: NR_STR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_url",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_url",
        args: &[],
        ret: NR_STR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_httpVersion",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_http_version",
        args: &[],
        ret: NR_STR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_complete",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_complete",
        args: &[],
        ret: NR_I32,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_aborted",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_aborted",
        args: &[],
        ret: NR_I32,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_destroyed",
        class_filter: Some("IncomingMessage"),
        runtime: "js_node_http_im_destroyed",
        args: &[],
        ret: NR_I32,
    },
    // Closes #769 followup — client-side `res.statusCode` /
    // `res.statusMessage` / `res.headers` after `http.request(url, cb)`.
    // The HIR registers the `res` arrow param as ("http",
    // "IncomingMessage"); these entries route the rewritten
    // `__get_<prop>` reads to perry-ext-http's accessor (the same
    // crate that owns the client-IncomingMessage registry the
    // response queue populates). (Restored after the #1099 squash-merge
    // dropped them via a conflict auto-resolution.)
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_statusCode",
        class_filter: Some("IncomingMessage"),
        runtime: "js_http_status_code",
        args: &[],
        ret: NR_F64,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_statusMessage",
        class_filter: Some("IncomingMessage"),
        runtime: "js_http_status_message",
        args: &[],
        ret: NR_STR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_headers",
        class_filter: Some("IncomingMessage"),
        runtime: "js_http_response_headers",
        args: &[],
        ret: NR_F64,
    },
    // PR #1146 belt-and-braces: bare-name dispatch for the same three
    // client-IncomingMessage properties, for sites where the HIR rewrite
    // to `__get_<prop>` doesn't fire (receiver isn't statically tagged
    // as ("http", "IncomingMessage"), e.g. one assigned through a local
    // before the property read).
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "statusCode",
        class_filter: Some("IncomingMessage"),
        runtime: "js_http_status_code",
        args: &[],
        ret: NR_F64,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "statusMessage",
        class_filter: Some("IncomingMessage"),
        runtime: "js_http_status_message",
        args: &[],
        ret: NR_STR,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "headers",
        class_filter: Some("IncomingMessage"),
        runtime: "js_http_response_headers",
        args: &[],
        ret: NR_F64,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_statusCode",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_get_status",
        args: &[],
        ret: NR_F64,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__set_statusCode",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_set_status",
        args: &[NA_F64],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__set_statusMessage",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_set_status_message",
        args: &[NA_STR],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_headersSent",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_headers_sent",
        args: &[],
        ret: NR_I32,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_writableEnded",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_writable_ended",
        args: &[],
        ret: NR_I32,
    },
    NativeModSig {
        module: "http",
        has_receiver: true,
        method: "__get_writableFinished",
        class_filter: Some("ServerResponse"),
        runtime: "js_node_http_res_writable_finished",
        args: &[],
        ret: NR_I32,
    },
    // ========== node:https server (issue #577 Phase 2) ==========
    NativeModSig {
        module: "https",
        has_receiver: false,
        method: "createServer",
        class_filter: None,
        runtime: "js_node_https_create_server",
        args: &[NA_F64, NA_PTR],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "https",
        has_receiver: true,
        method: "listen",
        class_filter: Some("HttpsServer"),
        runtime: "js_node_https_server_listen",
        args: &[NA_F64, NA_PTR],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "https",
        has_receiver: true,
        method: "close",
        class_filter: Some("HttpsServer"),
        runtime: "js_node_https_server_close",
        args: &[NA_PTR],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "https",
        has_receiver: true,
        method: "on",
        class_filter: Some("HttpsServer"),
        runtime: "js_node_https_server_on",
        args: &[NA_STR, NA_PTR],
        ret: NR_F64,
    },
    // ========== node:http2 server (issue #577 Phase 3) ==========
    NativeModSig {
        module: "http2",
        has_receiver: false,
        method: "createSecureServer",
        class_filter: None,
        runtime: "js_node_http2_create_secure_server",
        args: &[NA_F64, NA_PTR],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "http2",
        has_receiver: true,
        method: "listen",
        class_filter: Some("Http2SecureServer"),
        runtime: "js_node_http2_server_listen",
        args: &[NA_F64, NA_PTR],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http2",
        has_receiver: true,
        method: "close",
        class_filter: Some("Http2SecureServer"),
        runtime: "js_node_http2_server_close",
        args: &[NA_PTR],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "http2",
        has_receiver: true,
        method: "on",
        class_filter: Some("Http2SecureServer"),
        runtime: "js_node_http2_server_on",
        args: &[NA_STR, NA_PTR],
        ret: NR_F64,
    },
    // `@perryts/google-auth` is no longer bundled in perry-stdlib —
    // since v0.5.1015 the package is published as a standalone npm
    // module (https://github.com/PerryTS/google-auth). Codegen
    // dispatches `js_google_auth_*` symbols through `ffi_signatures`
    // built from the installed package's
    // `perry.nativeLibrary.functions`, same as any other external
    // nativeLibrary crate.
    // ========== perry/ads (issue #867) ==========
    // Six FFI entry points exported by `crates/perry-ext-ads`:
    //   - 4 promise-returning load/show pairs for interstitial +
    //     rewarded (NR_PTR — runtime sees a `*mut perry_ffi::Promise`
    //     and NaN-boxes via POINTER_TAG, same as bcrypt / argon2 /
    //     google-auth).
    //   - 2 synchronous banner create/destroy (NR_F64 / NR_VOID —
    //     banner_create returns a handle as a `number`, destroy is
    //     fire-and-forget).
    // MVP returns structured `{ error: "no-sdk-linked" }`
    // placeholders; real Google Mobile Ads SDK integration follows.
    NativeModSig {
        module: "perry/ads",
        has_receiver: false,
        method: "js_ads_interstitial_load",
        class_filter: None,
        runtime: "js_ads_interstitial_load",
        args: &[NA_STR],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "perry/ads",
        has_receiver: false,
        method: "js_ads_interstitial_show",
        class_filter: None,
        runtime: "js_ads_interstitial_show",
        args: &[],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "perry/ads",
        has_receiver: false,
        method: "js_ads_rewarded_load",
        class_filter: None,
        runtime: "js_ads_rewarded_load",
        args: &[NA_STR],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "perry/ads",
        has_receiver: false,
        method: "js_ads_rewarded_show",
        class_filter: None,
        runtime: "js_ads_rewarded_show",
        args: &[],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "perry/ads",
        has_receiver: false,
        method: "js_ads_banner_create",
        class_filter: None,
        runtime: "js_ads_banner_create",
        args: &[NA_STR, NA_STR],
        ret: NR_F64,
    },
    NativeModSig {
        module: "perry/ads",
        has_receiver: false,
        method: "js_ads_banner_destroy",
        class_filter: None,
        runtime: "js_ads_banner_destroy",
        args: &[NA_F64],
        ret: NR_VOID,
    },
];
