import $request from '$utils/request';

import entrust, {EntrustType} from '$utils/request/entrust';

import Notice from '$utils/class/notice';

export default {

    event: new Notice(),

    triggerHandleFollow(config,data){
        if (config) {
            let fetchKey = config.flat || 'flat';

            let flatVNode = config.vm && config.vm.$refs && config.vm.$refs[fetchKey];

            if (flatVNode) {

                if (data.status) {
                    flatVNode.flat_unshift(data.rid,data.data);
                } else {
                    flatVNode.flat_delete(data.rid);
                }

            }

        }
    },

    on(name,config:Record<string, any>){
        this.event.on(name, (data)=>{
            this.triggerHandleFollow(config,data);
        });
    },

    off(name){
        return this.event.off(name);
    },

    getRequestList(options:Record<string, any>={},page){

        // 如果为获取关注触发
        if (options.collect) {
            return this.getFollowRoomList(page);
        } else {
            return this.getRoomList(options,page);
        }

    },

    getRoomList(options,page){
        return $request({
            url:'room/get_room_list',
            data:options,
            page
        });
    },

    getFollowRoomList(page){
        return $request({
            url:'Usercollectroom/get_user_collect_list',
            page,
            token:true,
            entrust: entrust.getEntrust(EntrustType.followRoom)
        });
    },



}