import { QueryParams } from './recordsType'
import https from './request'
import { loginType, userForm, personTest, personCertificateTest, CertificateTest, personCertificateRow, personData, companyWalletTest, InfoTest, companyTest,
  companyData, headerTest, formType, headerRow,comBoTest, addType
} from './userType'
// 用户登录
export const login = (data: userForm) => {
  return https<loginType>({
    url: '/login',
    method: 'post',
    data,
    headers: {
      unToken: true
    }
  })
}

// 退出登录
export const loginOut = () => {
  return https({
    url: '/logout',
    method: 'post',
    headers: {
      unToken: true
    }
  })
}

export interface updateStateParams {
  relateId: number
  state: string
}

// 离职申请
export const updateState = (data: updateStateParams) => {
  return https({
    url: '/system/companyPerson/updateState',
    method: 'post',
    data
  })
}

// 获取账号信息
export const getInfo = () => {
  return https<InfoTest>({
    url: '/getInfo',
    method: 'get'
  })
}

// 获取个人信息
export const getPersonInfo = () => {
  return https<personTest>({
    url: '/system/person/currentPerson',
    method: 'get'
  })
}

// 获取公司管理员信息
export const getCompanyInfo = () => {
  return https<companyTest>({
    url: '/system/company/currentCompany',
    method: 'get'
  })
}

// 更新个人信息
export const updateCompanyInfo = (data: companyData) => {
  return https({
    url: '/system/company',
    method: 'put',
    data
  })
}

// 获取公司管理员获取员工信息
export const getPersonDetail = (personId: number) => {
  return https<personTest>({
    url: `/system/person/${personId}`,
    method: 'get'
  })
}

// 更新个人信息
export const updatePersonInfo = (data: personData) => {
  return https({
    url: '/system/person',
    method: 'put',
    data
  })
}

export interface emailType {
  code: number
  msg: string
  data: string
}

// 获取邮箱验证码
export const getEmailCode = (email: string) => {
  return https<emailType>({
    url: '/system/forgetPwd/registValidEmail',
    method: 'post',
    data: email
  })
}


export interface certificateParams {
  pageNum: number
  pageSize: number
  personId?: number
  companyId?: number
}

// 获取个人证书信息
export const getPersonalCertificate = (data: certificateParams) => {
  return https<personCertificateTest>({
    url: '/system/personalCertificate/list',
    method: 'get',
    params: data
  })
}

// 修改个人证书信息
export const updatePersonalCertificate = (data: personCertificateRow) => {
  return https({
    url: '/system/personalCertificate',
    method: 'put',
    data
  })
}

// 添加个人证书信息
export const addPersonalCertificate = (data: personCertificateRow) => {
  return https({
    url: '/system/personalCertificate',
    method: 'post',
    data
  })
}


// 获取证书列表
export const getCertificateList = (data: certificateParams) => {
  return https<CertificateTest>({
    url: '/system/certificate/list',
    method: 'get',
    params: data
  })
}

// 获取公司余额信息
export const getCompanyWallet = (data: certificateParams) => {
  return https<companyWalletTest>({
    url: '/system/wallet/list',
    method: 'get',
    params: data
  })
}

// 用户修改密码
export const updatePassword = (oldPassword: string, newPassword: string) => {
  return https<companyWalletTest>({
    url: '/system/user/profile/updatePwd',
    method: 'put',
    params: {
      oldPassword,
      newPassword
    }
  })
}

// 用户重置密码
export const resetPassword = (data: formType) => {
  return https({
    url: '/system/forgetPwd/resetPwd',
    method: 'post',
    data
  })
}

// 获取公司开票信息
export const getHeaderInfo = (data: QueryParams) => {
  return https<headerTest>({
    url: '/system/header/list',
    method: 'get',
    params: data
  })
}

// 修改新增开票信息
export const addHeaderInfo = (data: headerRow) => {
  return https({
    url: '/system/header',
    method: 'post',
    data
  })
}

// 修改开票信息
export const updateHeaderInfo = (data: headerRow) => {
  return https({
    url: '/system/header',
    method: 'put',
    data
  })
}

// 获取充值套餐
export const getComboList = (data: QueryParams) => {
  return https<comBoTest>({
    url: '/system/combo/list',
    method: 'get',
    params: data
  })
}

export  interface beanType {
  code: number
  msg: string
}

// 获取报告豆比例
export const getBean = () => {
  return https<beanType>({
    url: '/system/config/configKey/bean.config.proportion',
    method: 'get',
  })
}

// 获取是否可以上传云存储
export const getCloudDown = () => {
  return https<beanType>({
    url: '/system/config/configKey/permission.uploadVedio',
    method: 'get',
  })
}

// 获取是否收费
export const getPay = () => {
  return https<beanType>({
    url: '/system/config/configKey/permission.charge',
    method: 'get',
  })
}

export interface queryUserNameType {
  code: number
  msg: string
  data: number
}

// 检查用户名是否被使用
export const queryUsername = (userName: string) => {
  return https<queryUserNameType>({
    url: '/system/user/checkUserName',
    method: 'get',
    params: {
      userName
    }
  })
}

export interface queryIdNoType {
  code: number
  msg: string
  row: [],
  total: number
}

// 检查身份证号是否被使用
export const queryIdNo = (idNo: string) => {
  return https<queryIdNoType>({
    url: '/system/person/list',
    method: 'get',
    params: {
      pageNum: 1,
      pageSize: 1,
      idNo
    }
  })
}

// 注册个人用户
export const userRegister = (data: personData) => {
  return https({
    url: '/system/person/register',
    method: 'post',
    data
  })
}

// 注册企业用户
export const companyRegister = (data: companyData) => {
  return https({
    url: '/system/company/register',
    method: 'post',
    data
  })
}

// 公司新增员工
export const companyAdd = (data: addType) => {
  return https<beanType>({
    url: '/system/companyPerson',
    method: 'post',
    data
  })
}