use super::*;

pub(super) const ASYNC_DECIMAL_ROWS: &[NativeModSig] = &[
    // ========== async_hooks.AsyncLocalStorage ==========
    // `new AsyncLocalStorage()` is dispatched by `lower_builtin_new`; the rows
    // below cover the instance methods. `run(store, cb)` and `exit(cb)` need
    // the closure pointer arg coerced via NA_PTR (the runtime function takes
    // it as a raw `i64` ClosureHeader pointer + invokes `js_closure_call0`
    // internally). Pre-fix every method silently no-op'd through the
    // unknown-method sentinel.
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "run",
        class_filter: None,
        runtime: "js_async_local_storage_run",
        args: &[NA_F64, NA_PTR],
        ret: NR_F64,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "getStore",
        class_filter: None,
        runtime: "js_async_local_storage_get_store",
        args: &[],
        ret: NR_F64,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "enterWith",
        class_filter: None,
        runtime: "js_async_local_storage_enter_with",
        args: &[NA_F64],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "exit",
        class_filter: None,
        runtime: "js_async_local_storage_exit",
        args: &[NA_PTR],
        ret: NR_F64,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "disable",
        class_filter: None,
        runtime: "js_async_local_storage_disable",
        args: &[],
        ret: NR_VOID,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: false,
        method: "createHook",
        class_filter: None,
        runtime: "js_async_hooks_create_hook",
        args: &[NA_F64],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: false,
        method: "executionAsyncId",
        class_filter: None,
        runtime: "js_async_hooks_execution_async_id",
        args: &[],
        ret: NR_F64,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: false,
        method: "triggerAsyncId",
        class_filter: None,
        runtime: "js_async_hooks_trigger_async_id",
        args: &[],
        ret: NR_F64,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "enable",
        class_filter: Some("AsyncHook"),
        runtime: "js_async_hook_enable",
        args: &[],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "disable",
        class_filter: Some("AsyncHook"),
        runtime: "js_async_hook_disable",
        args: &[],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "asyncId",
        class_filter: Some("AsyncResource"),
        runtime: "js_async_resource_async_id",
        args: &[],
        ret: NR_F64,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "triggerAsyncId",
        class_filter: Some("AsyncResource"),
        runtime: "js_async_resource_trigger_async_id",
        args: &[],
        ret: NR_F64,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "emitDestroy",
        class_filter: Some("AsyncResource"),
        runtime: "js_async_resource_emit_destroy",
        args: &[],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "runInAsyncScope",
        class_filter: Some("AsyncResource"),
        runtime: "js_async_resource_run_in_async_scope",
        args: &[NA_PTR, NA_F64, NA_VARARGS],
        ret: NR_F64,
    },
    NativeModSig {
        module: "async_hooks",
        has_receiver: true,
        method: "bind",
        class_filter: Some("AsyncResource"),
        runtime: "js_async_resource_bind",
        args: &[NA_PTR],
        ret: NR_PTR,
    },
    // ========== decimal.js (arbitrary-precision math) ==========
    // `new Decimal(value)` is dispatched by `lower_builtin_new` (calls
    // `js_decimal_coerce_to_handle` to handle string/number/Decimal args).
    // The instance methods below all operate on a registered DecimalHandle.
    // Binary-op wrappers (`*_value`) coerce the second arg via the same
    // helper so `a.plus(2)` and `a.plus("0.1")` work as well as `a.plus(b)`.
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "plus",
        class_filter: None,
        runtime: "js_decimal_plus_value",
        args: &[NA_F64],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "minus",
        class_filter: None,
        runtime: "js_decimal_minus_value",
        args: &[NA_F64],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "times",
        class_filter: None,
        runtime: "js_decimal_times_value",
        args: &[NA_F64],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "div",
        class_filter: None,
        runtime: "js_decimal_div_value",
        args: &[NA_F64],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "mod",
        class_filter: None,
        runtime: "js_decimal_mod_value",
        args: &[NA_F64],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "pow",
        class_filter: None,
        runtime: "js_decimal_pow",
        args: &[NA_F64],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "sqrt",
        class_filter: None,
        runtime: "js_decimal_sqrt",
        args: &[],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "abs",
        class_filter: None,
        runtime: "js_decimal_abs",
        args: &[],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "neg",
        class_filter: None,
        runtime: "js_decimal_neg",
        args: &[],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "round",
        class_filter: None,
        runtime: "js_decimal_round",
        args: &[],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "floor",
        class_filter: None,
        runtime: "js_decimal_floor",
        args: &[],
        ret: NR_PTR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "ceil",
        class_filter: None,
        runtime: "js_decimal_ceil",
        args: &[],
        ret: NR_PTR,
    },
    // Formatting — return strings (NR_STR NaN-boxes the *StringHeader).
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "toFixed",
        class_filter: None,
        runtime: "js_decimal_to_fixed",
        args: &[NA_F64],
        ret: NR_STR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "toString",
        class_filter: None,
        runtime: "js_decimal_to_string",
        args: &[],
        ret: NR_STR,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "toNumber",
        class_filter: None,
        runtime: "js_decimal_to_number",
        args: &[],
        ret: NR_F64,
    },
    // `valueOf()` is what JS uses for implicit number coercion (e.g. `+a`,
    // `a < 5`); decimal.js documents it as an alias for toNumber.
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "valueOf",
        class_filter: None,
        runtime: "js_decimal_to_number",
        args: &[],
        ret: NR_F64,
    },
    // Comparisons — `*_value` wrappers coerce rhs so a.eq(0) works.
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "eq",
        class_filter: None,
        runtime: "js_decimal_eq_value",
        args: &[NA_F64],
        ret: NR_F64,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "lt",
        class_filter: None,
        runtime: "js_decimal_lt_value",
        args: &[NA_F64],
        ret: NR_F64,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "lte",
        class_filter: None,
        runtime: "js_decimal_lte_value",
        args: &[NA_F64],
        ret: NR_F64,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "gt",
        class_filter: None,
        runtime: "js_decimal_gt_value",
        args: &[NA_F64],
        ret: NR_F64,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "gte",
        class_filter: None,
        runtime: "js_decimal_gte_value",
        args: &[NA_F64],
        ret: NR_F64,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "cmp",
        class_filter: None,
        runtime: "js_decimal_cmp_value",
        args: &[NA_F64],
        ret: NR_F64,
    },
    // Predicates — return booleans encoded as f64 (TAG_TRUE / TAG_FALSE).
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "isZero",
        class_filter: None,
        runtime: "js_decimal_is_zero",
        args: &[],
        ret: NR_F64,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "isPositive",
        class_filter: None,
        runtime: "js_decimal_is_positive",
        args: &[],
        ret: NR_F64,
    },
    NativeModSig {
        module: "decimal.js",
        has_receiver: true,
        method: "isNegative",
        class_filter: None,
        runtime: "js_decimal_is_negative",
        args: &[],
        ret: NR_F64,
    },
];
