package com.yonge.cooleshow.biz.dal.vo.im;

import com.alibaba.fastjson.JSON;
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
import com.yonge.cooleshow.biz.dal.enums.ImGroupMemberRoleType;
import com.yonge.cooleshow.biz.dal.wrapper.VipCardRecordWrapper;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;
import java.util.Optional;

/**
 * Created by Eric.Shang on 2022/9/28.
 */
public class ImUserFriendVO {

    /**
     * 用户好友信息
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ImUserFriend implements Serializable {

        @ApiModelProperty(value = "主键;")
        private Long id;

        @ApiModelProperty(value = "当前用户编号")
        private Long userId;

        @ApiModelProperty(value = "好友编号")
        private String friendId;

        @ApiModelProperty(value = "融云好友编号")
        private String imFriendId;

        @ApiModelProperty(value = "好友身份")
        private ClientEnum friendType;

        @ApiModelProperty(value = "好友身份")
        private ClientEnum roleType;

        @ApiModelProperty(value = "好友头像")
        private String friendAvatar;

        @ApiModelProperty(value = "好友昵称")
        private String friendNickname;

        @ApiModelProperty(value = "备注")
        private String memo;

        @ApiModelProperty(value = "创建时间;")
        private Date createTime;

        @ApiModelProperty(value = "修改时间;")
        private Date updateTime;

        @ApiModelProperty(value = "好友会员信息")
        private VipCardRecordWrapper.UserVip userVip;

        @ApiModelProperty("声部")
        private String friendSubjectName;

        @ApiModelProperty("性别,1:男，0：女")
        private Integer friendGender;

        @ApiModelProperty("生日")
        private Date friendBirthdate;

        public static ImUserFriend from(String record) {

            return JSON.parseObject(record, ImUserFriend.class);
        }

        public ClientEnum getRoleType() {
            return getFriendType();
        }
    }

    /**
     * 群组成员信息
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ImGroupMember implements Serializable {

        @ApiModelProperty(value = "主键;")
        private Long id;

        @ApiModelProperty(value = "群编号;")
        private String groupId;

        @ApiModelProperty(value = "用户编号;")
        private String userId;

        @ApiModelProperty(value = "昵称;")
        private String nickname;

        @ApiModelProperty(value = "用户头像;")
        private String avatar;

        @ApiModelProperty(value = "是否是管理员")
        private Boolean isAdmin;

        @ApiModelProperty(value = "群角色TEACHER老师、STUDENT学生")
        private ImGroupMemberRoleType roleType;

        @ApiModelProperty(value = "创建时间;")
        private Date createTime;

        @ApiModelProperty(value = "修改时间;")
        private Date updateTime;

        @ApiModelProperty(value = "IM用户ID")
        private String imUserId;

        public static ImGroupMember from(String recv) {

            return JSON.parseObject(recv, ImGroupMember.class);
        }

        public String getUserId() {
            return Optional.ofNullable(getImUserId()).orElse(userId);
        }
    }


    /**
     * 用户好友信息
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ImMessageUser implements Serializable {


        @ApiModelProperty(value = "当前用户编号")
        private Long userId;

        @ApiModelProperty(value = "imUserId")
        private String imUserId;

        @ApiModelProperty("用户名称")
        private String username;

        @ApiModelProperty("用户头像")
        private String avatar;

        @ApiModelProperty("是否注销")
        private Boolean delFlag = false;
    }

}
