import FetchRequest from "@/api/FetchRequest";
import type Friend from "@/mode/Friend";

class FriendApi {
    static url = "/api/sys/friends";

    /**
     * 获取用户的所有好友
     * @param id 用户ID
     */
    static friends(): Promise<any> {
        return FetchRequest.get(`${this.url}?state=0`, true);
    }

    /**
     * 获取用户的待审核好友
     */
    static validateList(): Promise<any> {
        return FetchRequest.get(`${this.url}/validateList`, true);
    }

    /**
     * 添加好友
     * @param friend 好友
     */
    static add(friend: Friend): Promise<any> {
        return FetchRequest.post(`${this.url}/add`, JSON.stringify(friend), true);
    }

    /**
     * 审核好友
     * @param userId 用户ID
     * @param friendId 好友
     * @param state 状态
     */
    static check(userId: string, friendId: string, state: string): Promise<any> {
        const data = {
            friendId: friendId.toString(),
            state: state.toString(),
        };
        return FetchRequest.patch(
            `${this.url}/${userId}`,
            JSON.stringify(data),
            true
        );
    }

    /**
     * 同意加好友
     * @param friendId 好友ID
     */
    static agree(friendId: string): Promise<any> {
        return FetchRequest.post(`${this.url}/agree`, friendId, true);
    }

    /**
     * 删除好友
     * @param friendId 好友ID
     */
    static delete(friendId: string): Promise<any> {
        return FetchRequest.del(`${this.url}/delete`, friendId, true);
    }

    /**
     * 判断是否好友
     */
    static isFriend(friendId: string): Promise<any> {
        return FetchRequest.get(`${this.url}/isFriend?friendId=${friendId}`, true);
    }
}

export default FriendApi;
