package com.ustadmobile.core.db.dao

import com.google.gson.Gson
import com.ustadmobile.door.AbstractDoorUriResponder
import com.ustadmobile.door.DoorConstants
import com.ustadmobile.door.DoorDaoProvider
import com.ustadmobile.door.NanoHttpdCall
import com.ustadmobile.door.ext.DoorTag
import com.ustadmobile.door.room.RoomDatabase
import fi.iki.elonen.NanoHTTPD
import fi.iki.elonen.router.RouterNanoHTTPD
import kotlin.String
import kotlin.collections.Map
import kotlin.text.substringAfterLast
import org.kodein.di.DI
import org.kodein.di.Instance
import org.kodein.di.instance
import org.kodein.di.on
import org.kodein.type.TypeToken

public class XLangMapEntryDao_UriResponder : AbstractDoorUriResponder() {
  public override fun `get`(
    _uriResource: RouterNanoHTTPD.UriResource,
    _urlParams: Map<String, String>,
    _session: NanoHTTPD.IHTTPSession,
  ): NanoHTTPD.Response {
    val _fnName = _session.uri.substringAfterLast('/')
    val _di = _uriResource.initParameter(0, DI::class.java)
    val _daoProvider = _uriResource.initParameter(1, DoorDaoProvider::class.java) as
        DoorDaoProvider<RoomDatabase, XLangMapEntryDao>
    val _typeToken = _uriResource.initParameter(2, TypeToken::class.java) as TypeToken<RoomDatabase>
    val _call = NanoHttpdCall(_uriResource, _urlParams, _session)
    val _db: RoomDatabase by _di.on(_call).Instance(_typeToken, tag = DoorTag.TAG_DB)
    val _repo: RoomDatabase by _di.on(_call).Instance(_typeToken, tag = DoorTag.TAG_REPO)
    val _dao = _daoProvider.getDao(_db)
    val _gson : Gson by _di.instance()
    return NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.NOT_FOUND,
        DoorConstants.MIME_TYPE_PLAIN, "")
  }

  public override fun post(
    _uriResource: RouterNanoHTTPD.UriResource,
    _urlParams: Map<String, String>,
    _session: NanoHTTPD.IHTTPSession,
  ): NanoHTTPD.Response {
    val _fnName = _session.uri.substringAfterLast('/')
    val _di = _uriResource.initParameter(0, DI::class.java)
    val _daoProvider = _uriResource.initParameter(1, DoorDaoProvider::class.java) as
        DoorDaoProvider<RoomDatabase, XLangMapEntryDao>
    val _typeToken = _uriResource.initParameter(2, TypeToken::class.java) as TypeToken<RoomDatabase>
    val _call = NanoHttpdCall(_uriResource, _urlParams, _session)
    val _db: RoomDatabase by _di.on(_call).Instance(_typeToken, tag = DoorTag.TAG_DB)
    val _repo: RoomDatabase by _di.on(_call).Instance(_typeToken, tag = DoorTag.TAG_REPO)
    val _dao = _daoProvider.getDao(_db)
    val _gson : Gson by _di.instance()
    return NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.NOT_FOUND,
        DoorConstants.MIME_TYPE_PLAIN, "")
  }
}
