use std::collections::HashMap;
use std::ops::Index;

use crate::machine::PlutusVersion;

pub struct CostMap {
    map: HashMap<String, i64>,
}

impl CostMap {
    pub fn new(version: &PlutusVersion, values: &[i64]) -> Self {
        let keys = match version {
            PlutusVersion::V1 => vec![
                "add_integer-cpu-arguments-intercept",
                "add_integer-cpu-arguments-slope",
                "add_integer-mem-arguments-intercept",
                "add_integer-mem-arguments-slope",
                "append_byte_string-cpu-arguments-intercept",
                "append_byte_string-cpu-arguments-slope",
                "append_byte_string-mem-arguments-intercept",
                "append_byte_string-mem-arguments-slope",
                "append_string-cpu-arguments-intercept",
                "append_string-cpu-arguments-slope",
                "append_string-mem-arguments-intercept",
                "append_string-mem-arguments-slope",
                "b_data-cpu-arguments",
                "b_data-mem-arguments",
                "blake2b_256-cpu-arguments-intercept",
                "blake2b_256-cpu-arguments-slope",
                "blake2b_256-mem-arguments",
                "cek_apply_cost-exBudgetCPU",
                "cek_apply_cost-exBudgetmem",
                "cek_builtin_cost-exBudgetCPU",
                "cek_builtin_cost-exBudgetmem",
                "cek_const_cost-exBudgetCPU",
                "cek_const_cost-exBudgetmem",
                "cek_delay_cost-exBudgetCPU",
                "cek_delay_cost-exBudgetmem",
                "cek_force_cost-exBudgetCPU",
                "cek_force_cost-exBudgetmem",
                "cek_lam_cost-exBudgetCPU",
                "cek_lam_cost-exBudgetmem",
                "cek_startup_cost-exBudgetCPU",
                "cek_startup_cost-exBudgetmem",
                "cek_var_cost-exBudgetCPU",
                "cek_var_cost-exBudgetmem",
                "choose_data-cpu-arguments",
                "choose_data-mem-arguments",
                "choose_list-cpu-arguments",
                "choose_list-mem-arguments",
                "choose_unit-cpu-arguments",
                "choose_unit-mem-arguments",
                "cons_byte_string-cpu-arguments-intercept",
                "cons_byte_string-cpu-arguments-slope",
                "cons_byte_string-mem-arguments-intercept",
                "cons_byte_string-mem-arguments-slope",
                "constr_data-cpu-arguments",
                "constr_data-mem-arguments",
                "decode_utf8-cpu-arguments-intercept",
                "decode_utf8-cpu-arguments-slope",
                "decode_utf8-mem-arguments-intercept",
                "decode_utf8-mem-arguments-slope",
                "divide_integer-cpu-arguments-constant",
                "divide_integer-cpu-arguments-model-arguments-intercept",
                "divide_integer-cpu-arguments-model-arguments-slope",
                "divide_integer-mem-arguments-intercept",
                "divide_integer-mem-arguments-minimum",
                "divide_integer-mem-arguments-slope",
                "encode_utf8-cpu-arguments-intercept",
                "encode_utf8-cpu-arguments-slope",
                "encode_utf8-mem-arguments-intercept",
                "encode_utf8-mem-arguments-slope",
                "equals_byte_string-cpu-arguments-constant",
                "equals_byte_string-cpu-arguments-intercept",
                "equals_byte_string-cpu-arguments-slope",
                "equals_byte_string-mem-arguments",
                "equals_data-cpu-arguments-intercept",
                "equals_data-cpu-arguments-slope",
                "equals_data-mem-arguments",
                "equals_integer-cpu-arguments-intercept",
                "equals_integer-cpu-arguments-slope",
                "equals_integer-mem-arguments",
                "equals_string-cpu-arguments-constant",
                "equals_string-cpu-arguments-intercept",
                "equals_string-cpu-arguments-slope",
                "equals_string-mem-arguments",
                "fst_pair-cpu-arguments",
                "fst_pair-mem-arguments",
                "head_list-cpu-arguments",
                "head_list-mem-arguments",
                "i_data-cpu-arguments",
                "i_data-mem-arguments",
                "if_then_else-cpu-arguments",
                "if_then_else-mem-arguments",
                "index_byte_string-cpu-arguments",
                "index_byte_string-mem-arguments",
                "length_of_byte_string-cpu-arguments",
                "length_of_byte_string-mem-arguments",
                "less_than_byte_string-cpu-arguments-intercept",
                "less_than_byte_string-cpu-arguments-slope",
                "less_than_byte_string-mem-arguments",
                "less_than_equals_byte_string-cpu-arguments-intercept",
                "less_than_equals_byte_string-cpu-arguments-slope",
                "less_than_equals_byte_string-mem-arguments",
                "less_than_equals_integer-cpu-arguments-intercept",
                "less_than_equals_integer-cpu-arguments-slope",
                "less_than_equals_integer-mem-arguments",
                "less_than_integer-cpu-arguments-intercept",
                "less_than_integer-cpu-arguments-slope",
                "less_than_integer-mem-arguments",
                "list_data-cpu-arguments",
                "list_data-mem-arguments",
                "map_data-cpu-arguments",
                "map_data-mem-arguments",
                "mk_cons-cpu-arguments",
                "mk_cons-mem-arguments",
                "mk_nil_data-cpu-arguments",
                "mk_nil_data-mem-arguments",
                "mk_nil_pair_data-cpu-arguments",
                "mk_nil_pair_data-mem-arguments",
                "mk_pair_data-cpu-arguments",
                "mk_pair_data-mem-arguments",
                "mod_integer-cpu-arguments-constant",
                "mod_integer-cpu-arguments-model-arguments-intercept",
                "mod_integer-cpu-arguments-model-arguments-slope",
                "mod_integer-mem-arguments-intercept",
                "mod_integer-mem-arguments-minimum",
                "mod_integer-mem-arguments-slope",
                "multiply_integer-cpu-arguments-intercept",
                "multiply_integer-cpu-arguments-slope",
                "multiply_integer-mem-arguments-intercept",
                "multiply_integer-mem-arguments-slope",
                "null_list-cpu-arguments",
                "null_list-mem-arguments",
                "quotient_integer-cpu-arguments-constant",
                "quotient_integer-cpu-arguments-model-arguments-intercept",
                "quotient_integer-cpu-arguments-model-arguments-slope",
                "quotient_integer-mem-arguments-intercept",
                "quotient_integer-mem-arguments-minimum",
                "quotient_integer-mem-arguments-slope",
                "remainder_integer-cpu-arguments-constant",
                "remainder_integer-cpu-arguments-model-arguments-intercept",
                "remainder_integer-cpu-arguments-model-arguments-slope",
                "remainder_integer-mem-arguments-intercept",
                "remainder_integer-mem-arguments-minimum",
                "remainder_integer-mem-arguments-slope",
                "sha2_256-cpu-arguments-intercept",
                "sha2_256-cpu-arguments-slope",
                "sha2_256-mem-arguments",
                "sha3_256-cpu-arguments-intercept",
                "sha3_256-cpu-arguments-slope",
                "sha3_256-mem-arguments",
                "slice_byte_string-cpu-arguments-intercept",
                "slice_byte_string-cpu-arguments-slope",
                "slice_byte_string-mem-arguments-intercept",
                "slice_byte_string-mem-arguments-slope",
                "snd_pair-cpu-arguments",
                "snd_pair-mem-arguments",
                "subtract_integer-cpu-arguments-intercept",
                "subtract_integer-cpu-arguments-slope",
                "subtract_integer-mem-arguments-intercept",
                "subtract_integer-mem-arguments-slope",
                "tail_list-cpu-arguments",
                "tail_list-mem-arguments",
                "trace-cpu-arguments",
                "trace-mem-arguments",
                "un_b_data-cpu-arguments",
                "un_b_data-mem-arguments",
                "un_constr_data-cpu-arguments",
                "un_constr_data-mem-arguments",
                "un_i_data-cpu-arguments",
                "un_i_data-mem-arguments",
                "un_list_data-cpu-arguments",
                "un_list_data-mem-arguments",
                "un_map_data-cpu-arguments",
                "un_map_data-mem-arguments",
                "verify_ed25519_signature-cpu-arguments-intercept",
                "verify_ed25519_signature-cpu-arguments-slope",
                "verify_ed25519_signature-mem-arguments",
            ],
            PlutusVersion::V2 => vec![
                "add_integer-cpu-arguments-intercept",
                "add_integer-cpu-arguments-slope",
                "add_integer-mem-arguments-intercept",
                "add_integer-mem-arguments-slope",
                "append_byte_string-cpu-arguments-intercept",
                "append_byte_string-cpu-arguments-slope",
                "append_byte_string-mem-arguments-intercept",
                "append_byte_string-mem-arguments-slope",
                "append_string-cpu-arguments-intercept",
                "append_string-cpu-arguments-slope",
                "append_string-mem-arguments-intercept",
                "append_string-mem-arguments-slope",
                "b_data-cpu-arguments",
                "b_data-mem-arguments",
                "blake2b_256-cpu-arguments-intercept",
                "blake2b_256-cpu-arguments-slope",
                "blake2b_256-mem-arguments",
                "cek_apply_cost-exBudgetCPU",
                "cek_apply_cost-exBudgetmem",
                "cek_builtin_cost-exBudgetCPU",
                "cek_builtin_cost-exBudgetmem",
                "cek_const_cost-exBudgetCPU",
                "cek_const_cost-exBudgetmem",
                "cek_delay_cost-exBudgetCPU",
                "cek_delay_cost-exBudgetmem",
                "cek_force_cost-exBudgetCPU",
                "cek_force_cost-exBudgetmem",
                "cek_lam_cost-exBudgetCPU",
                "cek_lam_cost-exBudgetmem",
                "cek_startup_cost-exBudgetCPU",
                "cek_startup_cost-exBudgetmem",
                "cek_var_cost-exBudgetCPU",
                "cek_var_cost-exBudgetmem",
                "choose_data-cpu-arguments",
                "choose_data-mem-arguments",
                "choose_list-cpu-arguments",
                "choose_list-mem-arguments",
                "choose_unit-cpu-arguments",
                "choose_unit-mem-arguments",
                "cons_byte_string-cpu-arguments-intercept",
                "cons_byte_string-cpu-arguments-slope",
                "cons_byte_string-mem-arguments-intercept",
                "cons_byte_string-mem-arguments-slope",
                "constr_data-cpu-arguments",
                "constr_data-mem-arguments",
                "decode_utf8-cpu-arguments-intercept",
                "decode_utf8-cpu-arguments-slope",
                "decode_utf8-mem-arguments-intercept",
                "decode_utf8-mem-arguments-slope",
                "divide_integer-cpu-arguments-constant",
                "divide_integer-cpu-arguments-model-arguments-intercept",
                "divide_integer-cpu-arguments-model-arguments-slope",
                "divide_integer-mem-arguments-intercept",
                "divide_integer-mem-arguments-minimum",
                "divide_integer-mem-arguments-slope",
                "encode_utf8-cpu-arguments-intercept",
                "encode_utf8-cpu-arguments-slope",
                "encode_utf8-mem-arguments-intercept",
                "encode_utf8-mem-arguments-slope",
                "equals_byte_string-cpu-arguments-constant",
                "equals_byte_string-cpu-arguments-intercept",
                "equals_byte_string-cpu-arguments-slope",
                "equals_byte_string-mem-arguments",
                "equals_data-cpu-arguments-intercept",
                "equals_data-cpu-arguments-slope",
                "equals_data-mem-arguments",
                "equals_integer-cpu-arguments-intercept",
                "equals_integer-cpu-arguments-slope",
                "equals_integer-mem-arguments",
                "equals_string-cpu-arguments-constant",
                "equals_string-cpu-arguments-intercept",
                "equals_string-cpu-arguments-slope",
                "equals_string-mem-arguments",
                "fst_pair-cpu-arguments",
                "fst_pair-mem-arguments",
                "head_list-cpu-arguments",
                "head_list-mem-arguments",
                "i_data-cpu-arguments",
                "i_data-mem-arguments",
                "if_then_else-cpu-arguments",
                "if_then_else-mem-arguments",
                "index_byte_string-cpu-arguments",
                "index_byte_string-mem-arguments",
                "length_of_byte_string-cpu-arguments",
                "length_of_byte_string-mem-arguments",
                "less_than_byte_string-cpu-arguments-intercept",
                "less_than_byte_string-cpu-arguments-slope",
                "less_than_byte_string-mem-arguments",
                "less_than_equals_byte_string-cpu-arguments-intercept",
                "less_than_equals_byte_string-cpu-arguments-slope",
                "less_than_equals_byte_string-mem-arguments",
                "less_than_equals_integer-cpu-arguments-intercept",
                "less_than_equals_integer-cpu-arguments-slope",
                "less_than_equals_integer-mem-arguments",
                "less_than_integer-cpu-arguments-intercept",
                "less_than_integer-cpu-arguments-slope",
                "less_than_integer-mem-arguments",
                "list_data-cpu-arguments",
                "list_data-mem-arguments",
                "map_data-cpu-arguments",
                "map_data-mem-arguments",
                "mk_cons-cpu-arguments",
                "mk_cons-mem-arguments",
                "mk_nil_data-cpu-arguments",
                "mk_nil_data-mem-arguments",
                "mk_nil_pair_data-cpu-arguments",
                "mk_nil_pair_data-mem-arguments",
                "mk_pair_data-cpu-arguments",
                "mk_pair_data-mem-arguments",
                "mod_integer-cpu-arguments-constant",
                "mod_integer-cpu-arguments-model-arguments-intercept",
                "mod_integer-cpu-arguments-model-arguments-slope",
                "mod_integer-mem-arguments-intercept",
                "mod_integer-mem-arguments-minimum",
                "mod_integer-mem-arguments-slope",
                "multiply_integer-cpu-arguments-intercept",
                "multiply_integer-cpu-arguments-slope",
                "multiply_integer-mem-arguments-intercept",
                "multiply_integer-mem-arguments-slope",
                "null_list-cpu-arguments",
                "null_list-mem-arguments",
                "quotient_integer-cpu-arguments-constant",
                "quotient_integer-cpu-arguments-model-arguments-intercept",
                "quotient_integer-cpu-arguments-model-arguments-slope",
                "quotient_integer-mem-arguments-intercept",
                "quotient_integer-mem-arguments-minimum",
                "quotient_integer-mem-arguments-slope",
                "remainder_integer-cpu-arguments-constant",
                "remainder_integer-cpu-arguments-model-arguments-intercept",
                "remainder_integer-cpu-arguments-model-arguments-slope",
                "remainder_integer-mem-arguments-intercept",
                "remainder_integer-mem-arguments-minimum",
                "remainder_integer-mem-arguments-slope",
                "serialise_data-cpu-arguments-intercept",
                "serialise_data-cpu-arguments-slope",
                "serialise_data-mem-arguments-intercept",
                "serialise_data-mem-arguments-slope",
                "sha2_256-cpu-arguments-intercept",
                "sha2_256-cpu-arguments-slope",
                "sha2_256-mem-arguments",
                "sha3_256-cpu-arguments-intercept",
                "sha3_256-cpu-arguments-slope",
                "sha3_256-mem-arguments",
                "slice_byte_string-cpu-arguments-intercept",
                "slice_byte_string-cpu-arguments-slope",
                "slice_byte_string-mem-arguments-intercept",
                "slice_byte_string-mem-arguments-slope",
                "snd_pair-cpu-arguments",
                "snd_pair-mem-arguments",
                "subtract_integer-cpu-arguments-intercept",
                "subtract_integer-cpu-arguments-slope",
                "subtract_integer-mem-arguments-intercept",
                "subtract_integer-mem-arguments-slope",
                "tail_list-cpu-arguments",
                "tail_list-mem-arguments",
                "trace-cpu-arguments",
                "trace-mem-arguments",
                "un_b_data-cpu-arguments",
                "un_b_data-mem-arguments",
                "un_constr_data-cpu-arguments",
                "un_constr_data-mem-arguments",
                "un_i_data-cpu-arguments",
                "un_i_data-mem-arguments",
                "un_list_data-cpu-arguments",
                "un_list_data-mem-arguments",
                "un_map_data-cpu-arguments",
                "un_map_data-mem-arguments",
                "verify_ecdsa_secp256k1_signature-cpu-arguments",
                "verify_ecdsa_secp256k1_signature-mem-arguments",
                "verify_ed25519_signature-cpu-arguments-intercept",
                "verify_ed25519_signature-cpu-arguments-slope",
                "verify_ed25519_signature-mem-arguments",
                "verify_schnorr_secp256k1_signature-cpu-arguments-intercept",
                "verify_schnorr_secp256k1_signature-cpu-arguments-slope",
                "verify_schnorr_secp256k1_signature-mem-arguments",
            ],
            PlutusVersion::V3 => {
                let mut base_keys = vec![
                    "add_integer-cpu-arguments-intercept",
                    "add_integer-cpu-arguments-slope",
                    "add_integer-mem-arguments-intercept",
                    "add_integer-mem-arguments-slope",
                    "append_byte_string-cpu-arguments-intercept",
                    "append_byte_string-cpu-arguments-slope",
                    "append_byte_string-mem-arguments-intercept",
                    "append_byte_string-mem-arguments-slope",
                    "append_string-cpu-arguments-intercept",
                    "append_string-cpu-arguments-slope",
                    "append_string-mem-arguments-intercept",
                    "append_string-mem-arguments-slope",
                    "b_data-cpu-arguments",
                    "b_data-mem-arguments",
                    "blake2b_256-cpu-arguments-intercept",
                    "blake2b_256-cpu-arguments-slope",
                    "blake2b_256-mem-arguments",
                    "cek_apply_cost-exBudgetCPU",
                    "cek_apply_cost-exBudgetmem",
                    "cek_builtin_cost-exBudgetCPU",
                    "cek_builtin_cost-exBudgetmem",
                    "cek_const_cost-exBudgetCPU",
                    "cek_const_cost-exBudgetmem",
                    "cek_delay_cost-exBudgetCPU",
                    "cek_delay_cost-exBudgetmem",
                    "cek_force_cost-exBudgetCPU",
                    "cek_force_cost-exBudgetmem",
                    "cek_lam_cost-exBudgetCPU",
                    "cek_lam_cost-exBudgetmem",
                    "cek_startup_cost-exBudgetCPU",
                    "cek_startup_cost-exBudgetmem",
                    "cek_var_cost-exBudgetCPU",
                    "cek_var_cost-exBudgetmem",
                    "choose_data-cpu-arguments",
                    "choose_data-mem-arguments",
                    "choose_list-cpu-arguments",
                    "choose_list-mem-arguments",
                    "choose_unit-cpu-arguments",
                    "choose_unit-mem-arguments",
                    "cons_byte_string-cpu-arguments-intercept",
                    "cons_byte_string-cpu-arguments-slope",
                    "cons_byte_string-mem-arguments-intercept",
                    "cons_byte_string-mem-arguments-slope",
                    "constr_data-cpu-arguments",
                    "constr_data-mem-arguments",
                    "decode_utf8-cpu-arguments-intercept",
                    "decode_utf8-cpu-arguments-slope",
                    "decode_utf8-mem-arguments-intercept",
                    "decode_utf8-mem-arguments-slope",
                    "divide_integer-cpu-arguments-constant",
                    "divide_integer-cpu-arguments-c00",
                    "divide_integer-cpu-arguments-c01",
                    "divide_integer-cpu-arguments-c02",
                    "divide_integer-cpu-arguments-c10",
                    "divide_integer-cpu-arguments-c11",
                    "divide_integer-cpu-arguments-c20",
                    "divide_integer-cpu-arguments-minimum",
                    "divide_integer-mem-arguments-intercept",
                    "divide_integer-mem-arguments-minimum",
                    "divide_integer-mem-arguments-slope",
                    "encode_utf8-cpu-arguments-intercept",
                    "encode_utf8-cpu-arguments-slope",
                    "encode_utf8-mem-arguments-intercept",
                    "encode_utf8-mem-arguments-slope",
                    "equals_byte_string-cpu-arguments-constant",
                    "equals_byte_string-cpu-arguments-intercept",
                    "equals_byte_string-cpu-arguments-slope",
                    "equals_byte_string-mem-arguments",
                    "equals_data-cpu-arguments-intercept",
                    "equals_data-cpu-arguments-slope",
                    "equals_data-mem-arguments",
                    "equals_integer-cpu-arguments-intercept",
                    "equals_integer-cpu-arguments-slope",
                    "equals_integer-mem-arguments",
                    "equals_string-cpu-arguments-constant",
                    "equals_string-cpu-arguments-intercept",
                    "equals_string-cpu-arguments-slope",
                    "equals_string-mem-arguments",
                    "fst_pair-cpu-arguments",
                    "fst_pair-mem-arguments",
                    "head_list-cpu-arguments",
                    "head_list-mem-arguments",
                    "i_data-cpu-arguments",
                    "i_data-mem-arguments",
                    "if_then_else-cpu-arguments",
                    "if_then_else-mem-arguments",
                    "index_byte_string-cpu-arguments",
                    "index_byte_string-mem-arguments",
                    "length_of_byte_string-cpu-arguments",
                    "length_of_byte_string-mem-arguments",
                    "less_than_byte_string-cpu-arguments-intercept",
                    "less_than_byte_string-cpu-arguments-slope",
                    "less_than_byte_string-mem-arguments",
                    "less_than_equals_byte_string-cpu-arguments-intercept",
                    "less_than_equals_byte_string-cpu-arguments-slope",
                    "less_than_equals_byte_string-mem-arguments",
                    "less_than_equals_integer-cpu-arguments-intercept",
                    "less_than_equals_integer-cpu-arguments-slope",
                    "less_than_equals_integer-mem-arguments",
                    "less_than_integer-cpu-arguments-intercept",
                    "less_than_integer-cpu-arguments-slope",
                    "less_than_integer-mem-arguments",
                    "list_data-cpu-arguments",
                    "list_data-mem-arguments",
                    "map_data-cpu-arguments",
                    "map_data-mem-arguments",
                    "mk_cons-cpu-arguments",
                    "mk_cons-mem-arguments",
                    "mk_nil_data-cpu-arguments",
                    "mk_nil_data-mem-arguments",
                    "mk_nil_pair_data-cpu-arguments",
                    "mk_nil_pair_data-mem-arguments",
                    "mk_pair_data-cpu-arguments",
                    "mk_pair_data-mem-arguments",
                    "mod_integer-cpu-arguments-constant",
                    "mod_integer-cpu-arguments-c00",
                    "mod_integer-cpu-arguments-c01",
                    "mod_integer-cpu-arguments-c02",
                    "mod_integer-cpu-arguments-c10",
                    "mod_integer-cpu-arguments-c11",
                    "mod_integer-cpu-arguments-c20",
                    "mod_integer-cpu-arguments-minimum",
                    "mod_integer-mem-arguments-intercept",
                    "mod_integer-mem-arguments-slope",
                    "multiply_integer-cpu-arguments-intercept",
                    "multiply_integer-cpu-arguments-slope",
                    "multiply_integer-mem-arguments-intercept",
                    "multiply_integer-mem-arguments-slope",
                    "null_list-cpu-arguments",
                    "null_list-mem-arguments",
                    "quotient_integer-cpu-arguments-constant",
                    "quotient_integer-cpu-arguments-c00",
                    "quotient_integer-cpu-arguments-c01",
                    "quotient_integer-cpu-arguments-c02",
                    "quotient_integer-cpu-arguments-c10",
                    "quotient_integer-cpu-arguments-c11",
                    "quotient_integer-cpu-arguments-c20",
                    "quotient_integer-cpu-arguments-minimum",
                    "quotient_integer-mem-arguments-intercept",
                    "quotient_integer-mem-arguments-minimum",
                    "quotient_integer-mem-arguments-slope",
                    "remainder_integer-cpu-arguments-constant",
                    "remainder_integer-cpu-arguments-c00",
                    "remainder_integer-cpu-arguments-c01",
                    "remainder_integer-cpu-arguments-c02",
                    "remainder_integer-cpu-arguments-c10",
                    "remainder_integer-cpu-arguments-c11",
                    "remainder_integer-cpu-arguments-c20",
                    "remainder_integer-cpu-arguments-minimum",
                    "remainder_integer-mem-arguments-intercept",
                    "remainder_integer-mem-arguments-slope",
                    "serialise_data-cpu-arguments-intercept",
                    "serialise_data-cpu-arguments-slope",
                    "serialise_data-mem-arguments-intercept",
                    "serialise_data-mem-arguments-slope",
                    "sha2_256-cpu-arguments-intercept",
                    "sha2_256-cpu-arguments-slope",
                    "sha2_256-mem-arguments",
                    "sha3_256-cpu-arguments-intercept",
                    "sha3_256-cpu-arguments-slope",
                    "sha3_256-mem-arguments",
                    "slice_byte_string-cpu-arguments-intercept",
                    "slice_byte_string-cpu-arguments-slope",
                    "slice_byte_string-mem-arguments-intercept",
                    "slice_byte_string-mem-arguments-slope",
                    "snd_pair-cpu-arguments",
                    "snd_pair-mem-arguments",
                    "subtract_integer-cpu-arguments-intercept",
                    "subtract_integer-cpu-arguments-slope",
                    "subtract_integer-mem-arguments-intercept",
                    "subtract_integer-mem-arguments-slope",
                    "tail_list-cpu-arguments",
                    "tail_list-mem-arguments",
                    "trace-cpu-arguments",
                    "trace-mem-arguments",
                    "un_b_data-cpu-arguments",
                    "un_b_data-mem-arguments",
                    "un_constr_data-cpu-arguments",
                    "un_constr_data-mem-arguments",
                    "un_i_data-cpu-arguments",
                    "un_i_data-mem-arguments",
                    "un_list_data-cpu-arguments",
                    "un_list_data-mem-arguments",
                    "un_map_data-cpu-arguments",
                    "un_map_data-mem-arguments",
                    "verify_ecdsa_secp256k1_signature-cpu-arguments",
                    "verify_ecdsa_secp256k1_signature-mem-arguments",
                    "verify_ed25519_signature-cpu-arguments-intercept",
                    "verify_ed25519_signature-cpu-arguments-slope",
                    "verify_ed25519_signature-mem-arguments",
                    "verify_schnorr_secp256k1_signature-cpu-arguments-intercept",
                    "verify_schnorr_secp256k1_signature-cpu-arguments-slope",
                    "verify_schnorr_secp256k1_signature-mem-arguments",
                    "cek_constr_cost-exBudgetCPU",
                    "cek_constr_cost-exBudgetmem",
                    "cek_case_cost-exBudgetCPU",
                    "cek_case_cost-exBudgetmem",
                    "bls12_381_G1_add-cpu-arguments",
                    "bls12_381_G1_add-mem-arguments",
                    "bls12_381_G1_compress-cpu-arguments",
                    "bls12_381_G1_compress-mem-arguments",
                    "bls12_381_G1_equal-cpu-arguments",
                    "bls12_381_G1_equal-mem-arguments",
                    "bls12_381_G1_hashToGroup-cpu-arguments-intercept",
                    "bls12_381_G1_hashToGroup-cpu-arguments-slope",
                    "bls12_381_G1_hashToGroup-mem-arguments",
                    "bls12_381_G1_neg-cpu-arguments",
                    "bls12_381_G1_neg-mem-arguments",
                    "bls12_381_G1_scalarMul-cpu-arguments-intercept",
                    "bls12_381_G1_scalarMul-cpu-arguments-slope",
                    "bls12_381_G1_scalarMul-mem-arguments",
                    "bls12_381_G1_uncompress-cpu-arguments",
                    "bls12_381_G1_uncompress-mem-arguments",
                    "bls12_381_G2_add-cpu-arguments",
                    "bls12_381_G2_add-mem-arguments",
                    "bls12_381_G2_compress-cpu-arguments",
                    "bls12_381_G2_compress-mem-arguments",
                    "bls12_381_G2_equal-cpu-arguments",
                    "bls12_381_G2_equal-mem-arguments",
                    "bls12_381_G2_hashToGroup-cpu-arguments-intercept",
                    "bls12_381_G2_hashToGroup-cpu-arguments-slope",
                    "bls12_381_G2_hashToGroup-mem-arguments",
                    "bls12_381_G2_neg-cpu-arguments",
                    "bls12_381_G2_neg-mem-arguments",
                    "bls12_381_G2_scalarMul-cpu-arguments-intercept",
                    "bls12_381_G2_scalarMul-cpu-arguments-slope",
                    "bls12_381_G2_scalarMul-mem-arguments",
                    "bls12_381_G2_uncompress-cpu-arguments",
                    "bls12_381_G2_uncompress-mem-arguments",
                    "bls12_381_finalVerify-cpu-arguments",
                    "bls12_381_finalVerify-mem-arguments",
                    "bls12_381_millerLoop-cpu-arguments",
                    "bls12_381_millerLoop-mem-arguments",
                    "bls12_381_mulMlResult-cpu-arguments",
                    "bls12_381_mulMlResult-mem-arguments",
                    "keccak_256-cpu-arguments-intercept",
                    "keccak_256-cpu-arguments-slope",
                    "keccak_256-mem-arguments",
                    "blake2b_224-cpu-arguments-intercept",
                    "blake2b_224-cpu-arguments-slope",
                    "blake2b_224-mem-arguments-slope",
                    "integerToByteString-cpu-arguments-c0",
                    "integerToByteString-cpu-arguments-c1",
                    "integerToByteString-cpu-arguments-c2",
                    "integerToByteString-mem-arguments-intercept",
                    "integerToByteString-mem-arguments-slope",
                    "byteStringToInteger-cpu-arguments-c0",
                    "byteStringToInteger-cpu-arguments-c1",
                    "byteStringToInteger-cpu-arguments-c2",
                    "byteStringToInteger-mem-arguments-intercept",
                    "byteStringToInteger-mem-arguments-slope",
                ];

                // Newer parameter vectors may append extra entries after the known
                // bitwise/ripemd V3 costs. As long as we have at least that prefix,
                // keep mapping the known keys instead of silently dropping them.
                if values.len() >= 297 {
                    base_keys.extend([
                        "andByteString-cpu-arguments-intercept",
                        "andByteString-cpu-arguments-slope1",
                        "andByteString-cpu-arguments-slope2",
                        "andByteString-memory-arguments-intercept",
                        "andByteString-memory-arguments-slope",
                        "orByteString-cpu-arguments-intercept",
                        "orByteString-cpu-arguments-slope1",
                        "orByteString-cpu-arguments-slope2",
                        "orByteString-memory-arguments-intercept",
                        "orByteString-memory-arguments-slope",
                        "xorByteString-cpu-arguments-intercept",
                        "xorByteString-cpu-arguments-slope1",
                        "xorByteString-cpu-arguments-slope2",
                        "xorByteString-memory-arguments-intercept",
                        "xorByteString-memory-arguments-slope",
                        "complementByteString-cpu-arguments-intercept",
                        "complementByteString-cpu-arguments-slope",
                        "complementByteString-memory-arguments-intercept",
                        "complementByteString-memory-arguments-slope",
                        "readBit-cpu-arguments",
                        "readBit-memory-arguments",
                        "writeBits-cpu-arguments-intercept",
                        "writeBits-cpu-arguments-slope",
                        "writeBits-memory-arguments-intercept",
                        "writeBits-memory-arguments-slope",
                        "replicateByte-cpu-arguments-intercept",
                        "replicateByte-cpu-arguments-slope",
                        "replicateByte-memory-arguments-intercept",
                        "replicateByte-memory-arguments-slope",
                        "shiftByteString-cpu-arguments-intercept",
                        "shiftByteString-cpu-arguments-slope",
                        "shiftByteString-memory-arguments-intercept",
                        "shiftByteString-memory-arguments-slope",
                        "rotateByteString-cpu-arguments-intercept",
                        "rotateByteString-cpu-arguments-slope",
                        "rotateByteString-memory-arguments-intercept",
                        "rotateByteString-memory-arguments-slope",
                        "countSetBits-cpu-arguments-intercept",
                        "countSetBits-cpu-arguments-slope",
                        "countSetBits-memory-arguments",
                        "findFirstSetBit-cpu-arguments-intercept",
                        "findFirstSetBit-cpu-arguments-slope",
                        "findFirstSetBit-memory-arguments",
                        "ripemd_160-cpu-arguments-intercept",
                        "ripemd_160-cpu-arguments-slope",
                        "ripemd_160-memory-arguments",
                    ]);
                }
                base_keys
            }
        };

        let map = cost_map_from_keys_and_values(&keys, values);

        Self { map }
    }
}

fn cost_map_from_keys_and_values(keys: &[&str], values: &[i64]) -> HashMap<String, i64> {
    keys.iter()
        .cloned()
        .map(String::from)
        .zip(values.iter().cloned())
        .collect()
}

impl Index<&str> for CostMap {
    type Output = i64;
    fn index(&self, key: &str) -> &Self::Output {
        self.map.get(key).unwrap_or(&30000000000)
    }
}
