/** ================================= 客户资料 ================================**/

import { getUserId } from '@/services/bus/account';
import { BaseResponse, commonSearch_go, commonUpdate_go } from '@/services/go/index';
import {
    AddUserInfoApplyReq,
    DeleteUserReq,
    ModifyUserInfoApplyReq,
    ModifyUserInfoReq,
    QueryCustomInfoType, UpdateUserAccountReq
} from './interface';
import { QueryCustomInfoEnum } from './type';

/** ================================= 信息 客户资料 ================================**/
/**
 * 查询客户资料
 * @param MemberUserID  所属机构用户ID
 * @param queryType 查询类型(1:未提交 2:待审核 3:正常 4:停用)
 * @returns
 */
export function QueryCustomInfo(querytype: QueryCustomInfoEnum): Promise<QueryCustomInfoType[]> {
    const userid = getUserId()
    return commonSearch_go('/Qhj/QueryCustomerInfo', { userid, querytype }).catch((err) => {
        throw new Error(`查询客户资料: ${err}`);
    });
}

/**
 * 新增客户申请
 * @param userInfoApply
 * @constructor
 */
export function QueryAddUserInfoApply(userInfoApply: AddUserInfoApplyReq): Promise<BaseResponse> {
    return commonUpdate_go('/Erms3/AddUserInfoApply', userInfoApply).catch((err) => {
        throw new Error(`新增客户申请: ${err}`);
    });
}

/**
 * 修改客户申请 /Erms3/ModifyUserInfoApply
 * @param userInfoApply.userid: number;//用户ID(自增ID) (必填)
 * @param userInfoApply.userinfotype: number;//用户信息类型 - 1:个人 2:企业 (必填)
 * @param userInfoApply.username: string;//用户姓名 (必填)
 * @param userInfoApply.userstate: number;//开户状态 - 1:未提交 2: 待初审 3:初审拒绝 4:待复审 5:复审拒绝 6:测评不通过 (必填)
 * @param userInfoApply.customername: string;//客户名称(企业名称)  (必填)
 * @constructor
 */
export function QueryModifyUserInfoApply(userInfoApply: ModifyUserInfoApplyReq): Promise<BaseResponse> {
    return commonUpdate_go('/Erms3/ModifyUserInfoApply', userInfoApply).catch((err) => {
        throw new Error(`修改客户申请: ${err}`);
    });
}

/**
 * 撤回
 * @param req
 * @constructor
 */
export function QueryModifyUserInfo(req: ModifyUserInfoReq): Promise<BaseResponse> {
    return commonUpdate_go('/Erms3/ModifyUserInfoApply', req).catch((err) => {
        throw new Error(`修改客户申请状态: ${err}`);
    });
}


/**
 * 删除客户申请
 * @constructor
 * @param req
 */
export function QueryDeleteUserInfoApply(req: DeleteUserReq): Promise<string> {
    return commonSearch_go('/Erms3/DeleteUserInfoApply', req,)
        .then(() => 'ok')
        .catch((err) => {
            throw new Error(`删除客户申请: ${err}`);
        });
}

/**
 * 更新用户状态 /User/UpdateUserAccountStatus
 * @constructor
 * @param req
 */
export function UpdateUserAccountStatus(req: UpdateUserAccountReq): Promise<BaseResponse> {
    return commonUpdate_go('/User/UpdateUserAccountStatus', req,).catch((err) => {
        throw new Error(`更新用户状态: ${err}`);
    });
}
