import { GetStorage } from "../../../src/storage";

/**
 * This is the doc comment for pallet `<%= prefix %>`'s storages.
 * 
 * `<%= prefix %>`'s calls: {@link: module:<%= chainName %>/<%= moduleName %>/calls}
 *
 * @module <%= chainName %>/<%= moduleName %>/storages
 */
export const get<%= prefix %> = (getStorage: GetStorage) => {
    return {
<%_
    for(let i = 0; i < entries.length; i++) {
        const entry = entries[i];
        const inputTypeNames = entryInputTypes.get(entry.name.toString());
        const outputTypeName = outputTypes[i];
        const methodName = entry.name.charAt(0).toLowerCase() + entry.name.slice(1);
_%>

        /**
<%_
        entry.docs.forEach((doc) => {
_%>
         *<%- doc %>
<%_
        })
_%>
         *
<%_
        if(inputTypeNames) {
            for(let j = 0; j < inputTypeNames.length; j++) {
                const inputTypeName = inputTypeNames[j];
_%>
         * @param {unknown} param<%= j %> <%- inputTypeName %>
<%_
            }
        }
_%>
         * @returns {Promise<string | null>} <%- outputTypeName %>
         */
<%_
        if(entry.type.isPlain) {
_%>
        <%= methodName %>: async (): Promise<string | null> => {
            return await getStorage('<%= prefix %>', '<%= entry.name %>');
        },
<%_
        } else if(entry.type.isMap) {
            // const inputTypeNames = entryInputTypes.get(entry.name.toString());
            const len = entry.type.asMap.hashers.length;
            let input = [];
            let input2 = []
            for(let j = 0; j < len; j++) {
                // const typeName = inputTypeNames[j];
                // console.log(typeName);
                input.push(`param${j}: unknown`);
                input2.push(`param${j}`)
            }
_%>
        <%= methodName %>: async (<%= input.join(", ") %>): Promise<string | null> => {
            return await getStorage('<%= prefix %>', '<%= entry.name %>', <%= input2.join(", ") %>);
        },
<%_
        }
_%>
<%_
    }
_%>
    };
};
