/*
 * Copyright 2025 - 2026 PICO. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.pico.spatialui.sample.viewmodel

import androidx.lifecycle.ViewModel
import com.pico.spatialui.sample.R
import com.pico.spatialui.sample.model.User
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

class RelationshipViewModel : ViewModel() {
    private val _myFollowingList = MutableStateFlow<List<User>>(emptyList())
    val myFollowingList: StateFlow<List<User>> = _myFollowingList

    private val _myFollowerList = MutableStateFlow<List<User>>(emptyList())
    val myFollowerList: StateFlow<List<User>> = _myFollowerList

    private val _recommendedUserList = MutableStateFlow<List<User>>(emptyList())
    val recommendedUserList: StateFlow<List<User>> = _recommendedUserList

    private val _mutualList = MutableStateFlow<List<User>>(emptyList())
    val mutualList: StateFlow<List<User>> = _mutualList

    init {
        loadLocalData()
    }

    private fun loadLocalData() {
        val allUserList =
            listOf(
                User(
                    id = "id_x1",
                    imageId = R.drawable.img_avatar_1,
                    nameRes = R.string.sui_sample_user_name_x1,
                    descriptionRes = R.string.sui_sample_user_desc_x1,
                    hot = true,
                    isFollowing = true,
                    isFollower = true
                ),
                User(
                    id = "id_x2",
                    imageId = R.drawable.img_avatar_2,
                    nameRes = R.string.sui_sample_user_name_x2,
                    descriptionRes = R.string.sui_sample_user_desc_x2,
                    hot = false,
                    isFollowing = true,
                    isFollower = false
                ),
                User(
                    id = "id_x3",
                    imageId = R.drawable.img_avatar_3,
                    nameRes = R.string.sui_sample_user_name_x3,
                    descriptionRes = R.string.sui_sample_user_desc_x3,
                    hot = true,
                    isFollowing = true,
                    isFollower = true
                ),
                User(
                    id = "id_x4",
                    imageId = R.drawable.img_avatar_4,
                    nameRes = R.string.sui_sample_user_name_x4,
                    descriptionRes = R.string.sui_sample_user_desc_x4,
                    hot = true,
                    isFollowing = true,
                    isFollower = false
                ),
                User(
                    id = "id_x5",
                    imageId = R.drawable.img_avatar_5,
                    nameRes = R.string.sui_sample_user_name_x5,
                    descriptionRes = R.string.sui_sample_user_desc_x5,
                    hot = false,
                    isFollowing = true,
                    isFollower = true
                ),
                User(
                    id = "id_x6",
                    imageId = R.drawable.img_avatar_6,
                    nameRes = R.string.sui_sample_user_name_x6,
                    descriptionRes = R.string.sui_sample_user_desc_x6,
                    hot = false,
                    isFollowing = true,
                    isFollower = true
                ),
                User(
                    id = "id_x7",
                    imageId = R.drawable.img_avatar_7,
                    nameRes = R.string.sui_sample_user_name_x7,
                    descriptionRes = R.string.sui_sample_user_desc_x7,
                    hot = true,
                    isFollowing = true,
                    isFollower = false
                )
            )

        _myFollowingList.value = allUserList.filter { it.isFollowing }
        _myFollowerList.value = allUserList.filter { it.isFollower }
        _recommendedUserList.value = allUserList.filter { it.hot }
        _mutualList.value = allUserList.filter { it.isFollowing && it.isFollower }
    }
}
