import api from "./core/api";
import request from "./core/request";
/** 登陆 */
export function login(code: string) {
  const appid = "wx9f26d47068186f86";
  return request<Resp<API.LoginRespDto>>(api.loginDev + "/auth/oauth2/token", {
    method: "POST",
    header: {
      Authorization: "Basic Y2d0ZjpjZ3Rm",
      "CLIENT-TOC": "Y",
      "content-type": "application/x-www-form-urlencoded",
    },

    data: {
      grant_type: "mobile",
      mobile: `APP-SMS@${appid}_encrypt:MINI-_-${code}`,
    },
  });
}

export function getUserInfo() {
  return request<Resp<API.UserInfoRespDto>>(
    api.loginDev + "/app/app-user/info",
    {
      method: "GET",
      header: {
        "CLIENT-TOC": "Y",
      },
    }
  );
}
/** 更新信息 */
export function updateUserInfo(data: any) {
  return request(api.loginDev + "/app/app-user/edit", {
    method: "PUT",
    header: {
      "CLIENT-TOC": "Y",
    },
    data,
  });
}

/** 查询法人信息 */
export function queryAuthenticationInfo() {
  return request<Resp<any>>(
    api.authenticationUrl + "/hncy/entities/selectIsAuthentication",
    {
      method: "POST",
      header: {
        "CLIENT-TOC": "Y",
      },
    }
  );
}
/** 查询法人类型 */
export function queryAuthenticationTypes() {
  return request<Resp<API.TypeOfLegalPerson[]>>(
    api.authenticationUrl + "/hncy/entities/selectByEntityTypes",
    {
      method: "POST",
      header: {
        "CLIENT-TOC": "Y",
      },
    }
  );
}

/** 提交认证信息 */
export function submitAuthentication(data: any) {
  return request<Resp<any>>(
    api.authenticationUrl + "/hncy/entities/authenticationSMZS",
    {
      method: "POST",
      header: {
        "CLIENT-TOC": "Y",
      },
      data,
    }
  );
}

/** 获取法人信息 */
export function getMainBodyInfo(tel: string) {
  return request<Resp<any>>(
    api.authenticationUrl + "/hncy/entities/getEntityByTel",
    {
      method: "GET",
      header: {
        "CLIENT-TOC": "Y",
      },
      params: {
        tel,
      },
    }
  );
}
