import { API_FOLLOW_USER, API_USER_MESSAGES, API_FRIEND_MOMENTS, API_MY_FOLLOWINGS, API_MY_FRIENDS, API_USER_DASHBOARD, API_USER_PROFILE, API_USER_MOMENTS } from "./http/api";
import { request } from "./http/request";

//关注
export const followUser = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_FOLLOW_USER, method: 'POST', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

//取消关注
export const unfollowUser = (id) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_MY_FOLLOWINGS + '/' + id, method: 'DELETE', data: {}
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

//获取消息列表
export const getMessages = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_USER_MESSAGES, method: 'GET', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

export const getMyFriends = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_MY_FRIENDS, method: 'GET', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

export const getMyFollowings = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_MY_FOLLOWINGS, method: 'GET', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

export const getMyFollowers = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_FOLLOW_USER, method: 'GET', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

export const getUserDashBoard = () => {
    return new Promise((resolve, reject) => {
        request({
            url: API_USER_DASHBOARD, method: 'GET', data: {}
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

export const getUserProfile = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_USER_PROFILE, method: 'GET', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

export const getFriendMoments = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_FRIEND_MOMENTS, method: 'GET', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

export const getUserMoments = (params) => {
    return new Promise((resolve, reject) => {
        request({
            url: API_USER_MOMENTS, method: 'GET', data: { ...params }
        }).then(res => {
            resolve(res);
            // dispatch(loginSuccess(res));
        }).catch(e => {
            reject(e)
        })
    })
}

