namespace PhpEmbed {
    errordomain EmbedRuntimeError {
        RUNTIME
    }

    [CCode (cname = "valaphp_embed_call_no_args_to_string", cheader_filename = "call/static_call.h")]
    private extern static string? call_no_args_to_string (string function_name, out string? error_message);

    [CCode (cname = "valaphp_embed_call_no_args_output_to_string_and_print", cheader_filename = "call/static_call.h")]
    private extern static string? call_no_args_output_to_string_and_print (string function_name, out string? error_message);

    [CCode (cname = "valaphp_embed_call_no_args_to_bool", cheader_filename = "call/static_call.h")]
    private extern static bool call_no_args_to_bool (string function_name, out string? error_message);

    [CCode (cname = "valaphp_embed_call_bool_to_string", cheader_filename = "call/static_call.h")]
    private extern static string? call_bool_to_string (string function_name, bool value, out string? error_message);

    [CCode (cname = "valaphp_embed_call_bool_to_double", cheader_filename = "call/static_call.h")]
    private extern static double call_bool_to_double (string function_name, bool value, out string? error_message);

    [CCode (cname = "valaphp_embed_call_int_to_string", cheader_filename = "call/static_call.h")]
    private extern static string? call_int_to_string (string function_name, int64 value, out string? error_message);

    [CCode (cname = "valaphp_embed_call_double_to_double", cheader_filename = "call/static_call.h")]
    private extern static double call_double_to_double (string function_name, double value, out string? error_message);

    [CCode (cname = "valaphp_embed_call_double_int_int_to_double", cheader_filename = "call/static_call.h")]
    private extern static double call_double_int_int_to_double (string function_name, double value, int precision, int mode, out string? error_message);

    [CCode (cname = "valaphp_embed_call_string_to_string", cheader_filename = "call/static_call.h")]
    private extern static string? call_string_to_string (string function_name, string value, out string? error_message);

    [CCode (cname = "valaphp_embed_call_string_to_int", cheader_filename = "call/static_call.h")]
    private extern static int call_string_to_int (string function_name, string value, out string? error_message);

    [CCode (cname = "valaphp_embed_call_string_int_int_to_string", cheader_filename = "call/static_call.h")]
    private extern static string? call_string_int_int_to_string (string function_name, string value, int offset, int length, out string? error_message);

    [CCode (cname = "valaphp_embed_call_double_int_string_string_to_string", cheader_filename = "call/static_call.h")]
    private extern static string? call_double_int_string_string_to_string (string function_name, double value, int decimals, string dec_point, string thousands_sep, out string? error_message);

    [CCode (cname = "valaphp_embed_call_string_string_string_to_string", cheader_filename = "call/static_call.h")]
    private extern static string? call_string_string_string_to_string (string function_name, string first, string second, string third, out string? error_message);

    [CCode (cname = "valaphp_embed_call_string_string_to_int_or_minus_one", cheader_filename = "call/static_call.h")]
    private extern static int call_string_string_to_int_or_minus_one (string function_name, string first, string second, out string? error_message);

    [CCode (cname = "valaphp_embed_call_string_bool_to_bool", cheader_filename = "call/static_call.h")]
    private extern static bool call_string_bool_to_bool (string function_name, string value, bool flag, out string? error_message);

    private void throw_static_call_error (string function_name, string php_file, int php_line, string? error_message) throws Error {
        throw new EmbedRuntimeError.RUNTIME ("%s:%d: PHP %s failed: %s", php_file, php_line, function_name, error_message ?? "unknown error");
    }

    private string checked_static_string (string function_name, string php_file, int php_line, string? value, string? error_message) throws Error {
        if (error_message != null || value == null)
            throw_static_call_error (function_name, php_file, php_line, error_message);
        return value;
    }

    public string json_last_error_msg_static (string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("json_last_error_msg", php_file, php_line, call_no_args_to_string ("json_last_error_msg", out error_message), error_message);
    }

    public string token_name_static (int token_id, string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("token_name", php_file, php_line, call_int_to_string ("token_name", token_id, out error_message), error_message);
    }

    public string phpinfo_static (string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("phpinfo", php_file, php_line, call_no_args_output_to_string_and_print ("phpinfo", out error_message), error_message);
    }

    public string zend_version_static (string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("zend_version", php_file, php_line, call_no_args_to_string ("zend_version", out error_message), error_message);
    }

    public double round_static (double value, int precision, RoundMode mode, string php_file, int php_line) throws Error {
        string? error_message = null;
        double result = call_double_int_int_to_double ("round", value, precision, (int) mode, out error_message);
        if (error_message != null)
            throw_static_call_error ("round", php_file, php_line, error_message);
        return result;
    }

    public double microtime_float_static (string php_file, int php_line) throws Error {
        string? error_message = null;
        double result = call_bool_to_double ("microtime", true, out error_message);
        if (error_message != null)
            throw_static_call_error ("microtime", php_file, php_line, error_message);
        return result;
    }

    public string microtime_string_static (string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("microtime", php_file, php_line, call_bool_to_string ("microtime", false, out error_message), error_message);
    }

    public double floor_static (double value, string php_file, int php_line) throws Error {
        string? error_message = null;
        double result = call_double_to_double ("floor", value, out error_message);
        if (error_message != null)
            throw_static_call_error ("floor", php_file, php_line, error_message);
        return result;
    }

    public int strlen_static (string value, string php_file, int php_line) throws Error {
        string? error_message = null;
        int result = call_string_to_int ("strlen", value, out error_message);
        if (error_message != null)
            throw_static_call_error ("strlen", php_file, php_line, error_message);
        return result;
    }

    public string substr_static (string value, int offset, int length, string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("substr", php_file, php_line, call_string_int_int_to_string ("substr", value, offset, length, out error_message), error_message);
    }

    public string exec_static (string command, string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("exec", php_file, php_line, call_string_to_string ("exec", command, out error_message), error_message);
    }

    public string shell_exec_static (string command, string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("shell_exec", php_file, php_line, call_string_to_string ("shell_exec", command, out error_message), error_message);
    }

    public string file_get_contents_static (string path, string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("file_get_contents", php_file, php_line, call_string_to_string ("file_get_contents", path, out error_message), error_message);
    }

    public string trim_static (string value, string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("trim", php_file, php_line, call_string_to_string ("trim", value, out error_message), error_message);
    }

    public string ltrim_static (string value, string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("ltrim", php_file, php_line, call_string_to_string ("ltrim", value, out error_message), error_message);
    }

    public string rtrim_static (string value, string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("rtrim", php_file, php_line, call_string_to_string ("rtrim", value, out error_message), error_message);
    }

    public string number_format_static (double value, int decimals, string dec_point, string thousands_sep, string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("number_format", php_file, php_line, call_double_int_string_string_to_string ("number_format", value, decimals, dec_point, thousands_sep, out error_message), error_message);
    }

    public string str_replace_static (string search, string replacement, string value, string php_file, int php_line) throws Error {
        string? error_message = null;
        return checked_static_string ("str_replace", php_file, php_line, call_string_string_string_to_string ("str_replace", search, replacement, value, out error_message), error_message);
    }

    public int stripos_static (string haystack, string needle, string php_file, int php_line) throws Error {
        string? error_message = null;
        int result = call_string_string_to_int_or_minus_one ("stripos", haystack, needle, out error_message);
        if (error_message != null)
            throw_static_call_error ("stripos", php_file, php_line, error_message);
        return result;
    }

    public bool flush_static (string php_file, int php_line) throws Error {
        string? error_message = null;
        bool result = call_no_args_to_bool ("flush", out error_message);
        if (error_message != null)
            throw_static_call_error ("flush", php_file, php_line, error_message);
        return result;
    }

    public bool class_exists_static (string class_name, bool autoload, string php_file, int php_line) throws Error {
        string? error_message = null;
        bool result = call_string_bool_to_bool ("class_exists", class_name, autoload, out error_message);
        if (error_message != null)
            throw_static_call_error ("class_exists", php_file, php_line, error_message);
        return result;
    }

}
