sourceafQuickFlux::EntityScheme.fan

using gfx::Image
using flux::Flux
using flux::Resource
using afIoc::Inject

const class EntityScheme : UriScheme {

    static const Str schemeName := "quickflux"
    
    override Obj? get(Uri uri, Obj? base) {
        DatastoreSrc    datastoreSrc    := Utils.dependencyByType(DatastoreSrc#)
        IconSrc         iconSrc         := Utils.dependencyByType(IconSrc#)
        
        entityType  := QuickFluxModule.appType(uri.host.capitalize)
        entityId    := uri.name.toInt
        entity      := datastoreSrc.get(entityType).findById(entityId)

        return EntityEditResource(uri, entity, iconSrc[entity.displayIcon])
    }
}

internal class EntityEditResource : Resource {
    override Uri    uri
    override Image  icon
    Entity entity

    new make(Uri uri, Entity entity, Image? icon) { 
        this.uri    = uri 
        this.icon   = icon ?: Image(`fan://icons/x16/file.png`)
        this.entity = entity
    }
    
    override Str name()  { return entity.displayName }
    override Str toStr() { return entity.displayName }
}