package com.adealink.weparty.account.login.data

import android.os.Parcelable
import com.adealink.frame.base.AppBase
import com.adealink.frame.util.PackageUtil
import com.adealink.weparty.channel.getChannel
import com.adealink.weparty.commonui.recycleview.diffutil.BaseListItemData
import com.adealink.weparty.module.account.AccountLocalService
import com.adealink.weparty.module.profile.data.UserInfo
import com.google.gson.annotations.GsonNullable
import com.google.gson.annotations.Must
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize

enum class ThirdType(val value: String) {
    GOOGLE("google"),
    PHONE("phone"),
    EMAIL("mail"),
}

data class LoginReq(
    @SerializedName("data") val accessToken: String,

    // TODO: 移除seqid,移除剩余的全部字段
    @SerializedName("seqid") val seqId: Long = 0,
    @SerializedName("fbAccount") val fbAccount: String = "",//AccountLocalService.fbAccount,
    @SerializedName("thirdType") val thirdType: String = "",
    @SerializedName("country") val country: String = "",
    @SerializedName("deviceId") val deviceId: String = "",
    @SerializedName("newDeviceId") val newDeviceId: String = "",
    @SerializedName("channel") val channel: String = getChannel(),
    @SerializedName("fromSimulator") val simulator: Boolean = false,
    @SerializedName("virtualApk") val virtualApk: Boolean = false,
    @SerializedName("versionCode") val versionCode: Int = PackageUtil.getVersionCode(),
    @SerializedName("platform") val platform: String = AppBase.platform,
    @SerializedName("packageName") val packageName: String = PackageUtil.getPackageName(),
    @SerializedName("appsflyerId") val appsflyerId: String = "",
    @SerializedName("lang") val appLang: String = "", //APP语言
    @SerializedName("systemLang") val systemLang: String = "", //系统语言
    @SerializedName("simMcc") val simMcc: String = "", //SIM卡信息
    @SerializedName("tid") val tid: Long? = null,//单个fb创建多个账号时使用

    @SerializedName("deviceToken") val deviceToken: String? = null,
    @SerializedName("codeVerifier") val codeVerifier: String? = null, //tiktok登录需要传

    @GsonNullable
    @SerializedName("inviter") val inviter: String? = null, // 用于绑定邀请用户
    @GsonNullable
    @SerializedName("shareScene") val shareScene: String? = null, // 参见: ShareLinkSource
)

data class GoogleLoginReq(
    @SerializedName("data") val token: String,
)

data class TestLoginReq(
    @SerializedName("email") val email: String = AccountLocalService.testAccount,
)

@Parcelize
data class LoginResult(
    @SerializedName("token") val token: String,
    @SerializedName("refreshToken") val refreshToken: String,
    @SerializedName("userProfile") val userInfo: UserInfo,
    @SerializedName("reason") val reason: String,
    @SerializedName("expire") val expire: Long,
) : Parcelable

data class UserKickOutNotify(
    @SerializedName("roomId") val roomId: Long,
    @Must
    @SerializedName("kickUid") val kickUid: String,
    @Must
    @SerializedName("kickReason") val kickReason: Long,
)

data class BlockFunctionNotify(
    @SerializedName("seqid") val seqId: Long = 0,
    @Must
    @SerializedName("uid") val uid: Long,
    @GsonNullable
    @SerializedName("content") val content: String? = null,
)

data class BlockAccountNotify(
    @SerializedName("seqid") val seqId: Long = 0,
    @Must
    @SerializedName("uid") val uid: Long,
    @GsonNullable
    @SerializedName("content") val content: String? = null,
)

data class ReplaceUserInfoNotify(
    @SerializedName("seqid") val seqId: Long = 0,
    @Must
    @SerializedName("uid") val uid: Long,
    @GsonNullable
    @SerializedName("content") val content: String? = null,
)

data class PhoneLoginReq(
    @SerializedName("phoneNumber") val phoneNumber: String,
    @SerializedName("loginPassword") val loginPassword: String,
    @SerializedName("loginVerifyCode") val loginVerifyCode: String,
    @SerializedName("deviceId") val deviceId: String,
    @SerializedName("newDeviceId") val newDeviceId: String,
    @SerializedName("country") val country: String,
    @SerializedName("channel") val channel: String = getChannel(),
    @SerializedName("fromSimulator") val simulator: Boolean = false,
    @SerializedName("virtualApk") val virtualApk: Boolean = false,
    @SerializedName("appsflyerId") val appsflyerId: String = "",
    @SerializedName("deviceToken") val deviceToken: String? = null,
    @GsonNullable
    @SerializedName("inviter") val inviter: String? = null, // 用于绑定邀请用户
    @GsonNullable
    @SerializedName("shareScene") val shareScene: String? = null, // 参见: ShareLinkSource
)


enum class VerifyCodeType(val value: Int) {
    SMS(0),
    WHATSAPP(1),
}

data class GetVerifyCodeReq(
    @SerializedName("phoneNumber") val phoneNumber: String,
    @SerializedName("lang") val lang: String,
    @SerializedName("deviceId") val deviceId: String,
    @SerializedName("newDeviceId") val newDeviceId: String,
    @SerializedName("reasonCode") val reasonCode: Int,//发送验证码的原因: 0-登录 1-密码重置 ,
    @SerializedName("otpType") val otpType: Int // 验证码渠道：0-默认短信,1-whatsapp ,
)

data class SetPhonePasswordReq(
    @SerializedName("phoneNumber") val phoneNumber: String,
    @SerializedName("oldPassword") val oldPassword: String, //老密码
    @SerializedName("password") val password: String, //新密码
)

data class RefreshTokenReq(
    @SerializedName("expiredToken") val expiredToken: String,
    @SerializedName("refreshToken") val refreshToken: String,
)

data class RefreshTokenNotify(
    @SerializedName("seqId") val seqId: Long,
)


@Parcelize
data class EmailCodeResult(
    @SerializedName("seqId") val seqId: Long,
    @SerializedName("mailAccount") val mailAccount: String,
    @SerializedName("verifyCode") val verifyCode: String,
    @SerializedName("tempToken") val tempToken: String,
) : Parcelable

enum class EmailType(val type: Int) {
    FRAGMENT_BIND_FIRST(1),
    FRAGMENT_BIND_SECOND(2),
}

enum class BindState(val state: Int) {
    EMAIL_BIND(1),
    EMAIL_UNBIND(2)
}

enum class EmailClickType(val type: Int) {
    CALLBACK_CLICK(1),
    CALLBACK_CONFIRM(2)
}

data class GetEmailReq(
    @SerializedName("mailAccount") val mailAccount: String,
    @SerializedName("deviceId") val deviceId: String,
    @SerializedName("newDeviceId") val newDeviceId: String,
    @SerializedName("reasonCode") val reasonCode: Int,
    @SerializedName("seqId") val seqId: Long = 0
)

data class VerifyMailCodeReq(
    @SerializedName("mailAccount") val mailAccount: String,
    @SerializedName("verifyCode") val verifyCode: String,
    @SerializedName("reasonCode") val reasonCode: Int,
    @SerializedName("seqId") val seqId: Long = 0
)

data class BindMailReq(
    @SerializedName("verifyCode") val verifyCode: String,
    @SerializedName("mailAccount") val mailAccount: String,
    @SerializedName("mailPassword") val mailPassword: String,
)


data class EmailResetPwdReq(
    @SerializedName("mailAccount") val mailAccount: String,
    @SerializedName("mailPassword") val mailPassword: String,
    @SerializedName("verifyCode") val verifyCode: String,
    @SerializedName("seqId") val seqId: Long = 0
)

data class EmailLoginReq(
    @SerializedName("mailAccount") val mailAccount: String,
    @SerializedName("mailPassword") val mailPassword: String,
    @SerializedName("thirdType") val thirdType: String,
    @SerializedName("deviceId") val deviceId: String,
    @SerializedName("newDeviceId") val newDeviceId: String,
    @SerializedName("channel") val channel: String = getChannel(),
    @SerializedName("fromSimulator") val simulator: Boolean = false,
    @SerializedName("virtualApk") val virtualApk: Boolean = false,
    @SerializedName("versionCode") val versionCode: Int = PackageUtil.getVersionCode(),
    @SerializedName("platform") val platform: String = AppBase.platform,
    @SerializedName("packageName") val packageName: String = PackageUtil.getPackageName(),
    @SerializedName("appsflyerId") val appsflyerId: String = "",
    @SerializedName("friendShareCode") val friendShareCode: String? = null,
    @GsonNullable
    @SerializedName("inviter") val inviter: String? = null, // 用于绑定邀请用户
    @GsonNullable
    @SerializedName("shareScene") val shareScene: String? = null, // 参见: ShareLinkSource
)


data class EmailCodeLoginReq(
    @SerializedName("mailAccount") val mailAccount: String,
    @SerializedName("mailVerifyCode") val mailCode: String,
    @SerializedName("thirdType") val thirdType: String,
    @SerializedName("deviceId") val deviceId: String,
    @SerializedName("newDeviceId") val newDeviceId: String,
    @SerializedName("channel") val channel: String = getChannel(),
    @SerializedName("fromSimulator") val simulator: Boolean = false,
    @SerializedName("virtualApk") val virtualApk: Boolean = false,
    @SerializedName("versionCode") val versionCode: Int = PackageUtil.getVersionCode(),
    @SerializedName("platform") val platform: String = AppBase.platform,
    @SerializedName("packageName") val packageName: String = PackageUtil.getPackageName(),
    @SerializedName("appsflyerId") val appsflyerId: String = "",
    @SerializedName("friendShareCode") val friendShareCode: String? = null,
)

data class EmailGoogleAccountReq(
    @SerializedName("deviceId") val deviceId: String,
    @SerializedName("newDeviceId") val newDeviceId: String,
)

data class ThirdAccountListResult(
    @SerializedName("thirdAccountList") val thirdAccountList: ArrayList<ThirdAccountListData>,
    @SerializedName("name") val name: String,
    @SerializedName("email") val email: String,
)

@Parcelize
data class ThirdAccountListData(
    @SerializedName("tid") val tid: Long,
    @SerializedName("userInfo") val userInfo: UserInfo,
    @SerializedName("latestLoginTs") val latestLoginTs: Long,
) : Parcelable

@Parcelize
data class FBAccountListData(
    val tid: Long,
    val userInfo: UserInfo,
    val isLastUsedAccount: Boolean = false,
) : Parcelable, BaseListItemData {

    override fun areItemsTheSame(newItem: Any): Boolean {
        return newItem is FBAccountListData && tid == newItem.tid && userInfo.uid == newItem.userInfo.uid
    }
}

enum class EmailReason(val reason: Int) {
    BIND_EMAIL(0),
    RESET_PWD(1),
    GOOGLE_LOGIN(2)
}

data class AccountInfo(
    @SerializedName("bindEmail") val bindEmail: String, //用户绑定的邮箱
    @SerializedName("password") val password: String, //密码
    @SerializedName("passwordWrongCount") val passwordWrongCount: Long, //密码登录输错次数
    @SerializedName("registMethod") val registMethod: String, //账户注册方式
    @SerializedName("registPhoneNumber") val registPhoneNumber: String, //账户注册手机号
    @SerializedName("registerTime") val registerTime: Long, //注册时间
    @SerializedName("relatedEmail") val relatedEmail: String, //用户关联使用的邮箱
    @SerializedName("uid") val uid: Long, //用户uid
)

data class BindAccountWithPhoneReq(
    @SerializedName("phoneNumber") val phoneNumber: String,//手机号;需要填写区号
    @SerializedName("verifyCode") val verifyCode: String,//验证码
)