package com.yutou.biliapi.bean.live;

import com.yutou.biliapi.bean.live.database.LiveConfigDatabaseBean;
import com.yutou.biliapi.databases.BiliLiveConfigDatabase;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.math.BigInteger;
import java.util.Objects;

@Data
public class LiveRoomConfig {
    String loginUid;
    String roomId;
    String anchorName;
    boolean isLogin;
    String rootPath="live";
    LiveDanmuInfo liveInfo;
    LiveRoomInfo roomInfo;

    public String getLoginUid() {
        if("null".equals(loginUid)){
            loginUid=null;
        }
        return loginUid;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        LiveRoomConfig that = (LiveRoomConfig) o;
        return Objects.equals(roomId, that.roomId);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(roomId);
    }

    public static LiveRoomConfig buildConfig(String roomId){
        BiliLiveConfigDatabase database = new BiliLiveConfigDatabase();
        LiveConfigDatabaseBean bean = database.getConfig(new String(roomId));
        database.close();
        LiveRoomConfig config = new LiveRoomConfig();
        config.setLoginUid(bean.getRecordUid());
        config.setRoomId(bean.getRoomId());
        config.setAnchorName(bean.getAnchorName());
        config.setLogin(StringUtils.hasText(bean.getRecordUid()));
        config.setRootPath(bean.getRecordPath());
        return config;
    }
}
