import {
    RecordQueryParam,
    RecordPageResult,
    SecondRecordQueryParam,
    SecondRecordPageResult,
    RankQueryParam,
    RankPageResult,
    AlterRankParam,
    AgentApplyQueryParam,
    AgentApplyPageResult,
} from "@/types/api/invitation/index";
import request from "@/utils/request";
import { AxiosPromise } from "axios";

/**
 * 查询邀请记录
 * @param data
 */
export function inviteRecord(
    data: RecordQueryParam
): AxiosPromise<RecordPageResult> {
    return request({
        url: "admin/invite/management/query",
        method: "post",
        data: data,
    });
}

/**
 * 根据id查询二级邀请
 * @param data
 */
export function inviteSecondRecord(
    data: SecondRecordQueryParam
): AxiosPromise<SecondRecordPageResult> {
    return request({
        url: "admin/invite/management/info",
        method: "post",
        data: data,
    });
}

/**
 * 查询邀请排名
 * @param data
 */
export function inviteRank(data: RankQueryParam): AxiosPromise<RankPageResult> {
    return request({
        url: "admin/invite/management/rank",
        method: "post",
        data: data,
    });
}

/**
 * 更新邀请排名
 * @param data
 */
export function alterRank(data: AlterRankParam): any {
    return request({
        url: "admin/invite/management/update-rank",
        method: "post",
        params: data,
    });
}

/**
 * 查询团队详情
 * @param data
 */
export function teamDetails(
    data: RecordQueryParam
): AxiosPromise<RecordPageResult> {
    return request({
        url: "admin/member/agent/page",
        method: "post",
        params: data,
    });
}

/**
 * 分页查询代理商申请列表
 */
export function agentApplyPageQuery(
    data: AgentApplyQueryParam
): AxiosPromise<AgentApplyPageResult> {
    return request({
        url: "admin/agent/apply/page-query",
        method: "post",
        params: data,
    });
}

/**
 * 代理商申请审核通过
 */
export function agentApplyPass(id: number): AxiosPromise<any> {
    return request({
        url: `admin/agent/apply/${id}/pass`,
        method: "patch",
    });
}

/**
 * 代理商申请审核拒绝
 */
export function agentApplyReject(
    id: number,
    rejectReason: string
): AxiosPromise<any> {
    return request({
        url: `admin/agent/apply/${id}/reject`,
        method: "patch",
        params: { rejectReason },
    });
}
