class ResourceService {
    async get(name) {
        const resource_mod = await import(`../resource/${name}.resource.js`)
        if ( !resource_mod ) throw new Error(`Unable to fetch resource ${name}.`)

        if ( !this.object_name(name) in resource_mod )
            throw new Error(`Unable to retrieve resource from module (${this.object_name(name)}).`)

        return resource_mod[this.object_name(name)]
    }

    object_name(name) {
        return name.toLowerCase().replace(/\//g, '_')
    }
}

const resource_service = new ResourceService()
export { resource_service }
