package de.sebse.fuplanner2.auth

import org.json.JSONObject

class UserCookies {
    var idpJsessionId: String? = null
    var wbJsessionId: String? = null
    var wbShibKey: String? = null
    var wbShibValue: String? = null
    var bbJsessionId: String? = null
    var bbSessionId: String? = null
    var bbSSessionId: String? = null
    var bbShibKey: String? = null
    var bbShibValue: String? = null

    constructor() { }

    constructor(json: String) {
        val obj = JSONObject(json)
        idpJsessionId = obj.opt("idpJsessionId") as String?
        wbJsessionId = obj.opt("wbJsessionId") as String?
        wbShibKey = obj.opt("wbShibKey") as String?
        wbShibValue = obj.opt("wbShibValue") as String?
        bbJsessionId = obj.opt("bbJsessionId") as String?
        bbSessionId = obj.opt("bbSessionId") as String?
        bbSSessionId = obj.opt("bbSSessionId") as String?
        bbShibKey = obj.opt("bbShibKey") as String?
        bbShibValue = obj.opt("bbShibValue") as String?
    }

    fun update(user: UserCookies) {
        idpJsessionId = user.idpJsessionId?: idpJsessionId
        wbJsessionId = user.wbJsessionId?: wbJsessionId
        wbShibKey = user.wbShibKey?: wbShibKey
        wbShibValue = user.wbShibValue?: wbShibValue
        bbJsessionId = user.bbJsessionId?: bbJsessionId
        bbSessionId = user.bbSessionId?: bbSessionId
        bbSSessionId = user.bbSSessionId?: bbSSessionId
        bbShibKey = user.bbShibKey?: bbShibKey
        bbShibValue = user.bbShibValue?: bbShibValue
    }

    override fun toString(): String {
        val obj = JSONObject()
        obj.put("idpJsessionId", idpJsessionId)
        obj.put("wbJsessionId", wbJsessionId)
        obj.put("wbShibKey", wbShibKey)
        obj.put("wbShibValue", wbShibValue)
        obj.put("bbJsessionId", bbJsessionId)
        obj.put("bbSessionId", bbSessionId)
        obj.put("bbSSessionId", bbSSessionId)
        obj.put("bbShibKey", bbShibKey)
        obj.put("bbShibValue", bbShibValue)
        return obj.toString()
    }
}