package com.yutou.bilibili.BiliBili.Tools;

import com.yutou.bilibili.BiliBili.Services.IBiliBiliLiveService;
import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliLiveInfo;
import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliUpInfo;
import org.java_websocket.client.WebSocketClient;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;

public class LiveT implements ApplicationContextAware {
    private static ApplicationContext applicationContext = null;

    IBiliBiliLiveService service;


    public static List<LiveT> list=new ArrayList<>();
    int v;

    @PostConstruct
    public void init() {
        com.yutou.bilibili.Tools.Log.i("初始化2");
    }

    public LiveT() {
        com.yutou.bilibili.Tools.Log.i("初始化");
    }

    public void add(int a){

        v=a;
        BilibiliUpInfo info=new BilibiliUpInfo();
        info.setRoomid(a);
        info.setOfflinelistening(0);
        info.setSavedanmu(0);
        info.setEnable(0);
        info.setLive(0);
        info.setSavelive(0);
        info.setName("a"+a);
        info.setUrl("#");
        service=getBean(IBiliBiliLiveService.class);
        service.addUpInfo(info);
    }
    public int get(){
        return v;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        if(LiveT.applicationContext==null){
            LiveT.applicationContext=applicationContext;
        }
    }
    public static <T> T getBean(Class<T> clazz){
        return applicationContext.getBean(clazz);
    }
}
