package com.aiosman.ravenow.data

import com.aiosman.ravenow.AppStore
import com.aiosman.ravenow.data.api.ApiClient
import com.aiosman.ravenow.entity.AgentEntity
import com.aiosman.ravenow.entity.CreatorEntity
import com.aiosman.ravenow.entity.ProfileEntity
import com.aiosman.ravenow.entity.RoomEntity
import com.aiosman.ravenow.entity.UsersEntity
import com.google.gson.annotations.SerializedName

data class Room(
    @SerializedName("id")
    val id: Int,
    @SerializedName("name")
    val name: String,
    @SerializedName("description")
    val description: String,
    @SerializedName("trtcRoomId")
    val trtcRoomId: String,
    @SerializedName("trtcType")
    val trtcType: String,
    @SerializedName("cover")
    val cover: String,
    @SerializedName("avatar")
    val avatar: String,
    @SerializedName("recommendBanner")
    val recommendBanner: String,
    @SerializedName("isRecommended")
    val isRecommended: Boolean,
    @SerializedName("allowInHot")
    val allowInHot: Boolean,
    @SerializedName("creator")
    val creator: Creator,
    @SerializedName("userCount")
    val userCount: Int,
    @SerializedName("maxMemberLimit")
    val maxMemberLimit: Int,
    @SerializedName("canJoin")
    val canJoin: Boolean,
    @SerializedName("canJoinCode")
    val canJoinCode: Int,
    @SerializedName("users")
    val users: List<Users>

    ) {
    fun toRoomtEntity(): RoomEntity {
        return RoomEntity(
        id= id,
        name = name,
        description = description ,
        trtcRoomId = trtcRoomId,
        trtcType = trtcType,
        cover =  cover,
        avatar = avatar,
        recommendBanner = recommendBanner,
        isRecommended = isRecommended,
        allowInHot = allowInHot,
        creator = creator.toCreatorEntity(),
        userCount = userCount,
        maxMemberLimit = maxMemberLimit,
        canJoin = canJoin,
        canJoinCode = canJoinCode,
            users = users.map { it.toUsersEntity() }
        )
    }
}


data class Creator(
    @SerializedName("id")
    val id: Int,
    @SerializedName("userId")
    val userId: String,
    @SerializedName("trtcUserId")
    val trtcUserId: String,
    @SerializedName("profile")
    val profile: Profile
){
    fun toCreatorEntity(): CreatorEntity {
        return CreatorEntity(
            id = id,
            userId = userId,
            trtcUserId = trtcUserId,
            profile = profile.toProfileEntity()
        )
    }
}

data class Users(
    @SerializedName("id")
    val id: Int,
    @SerializedName("userId")
    val userId: String,
    @SerializedName("trtcUserId")
    val trtcUserId: String,
    @SerializedName("profile")
    val profile: Profile
){
    fun toUsersEntity(): UsersEntity {
        return UsersEntity(
            id = id,
            userId = userId,
            profile = profile.toProfileEntity()
        )
    }
}




