/**
 * 认证相关 API
 * @author steelwei
 */
import request from '@/utils/request'
import { CLIENT_ID, TENANT_ID, PLATFORM_ID } from '@/utils/config'

/**
 * 密码登录
 * @param {string} username - 手机号
 * @param {string} password - 密码
 */
export function loginByPassword(username, password) {
  return request({
    url: '/auth/login',
    method: 'POST',
    needToken: false,
    data: {
      tenantId: TENANT_ID,
      platformId: PLATFORM_ID,
      username,
      password,
      clientId: CLIENT_ID,
      grantType: 'fulfiller_password' // 使用履约者专用认证策略
    }
  })
}

/**
 * 短信验证码登录
 * @param {string} phonenumber - 手机号
 * @param {string} smsCode - 验证码
 */
export function loginBySms(phonenumber, smsCode) {
  return request({
    url: '/auth/login',
    method: 'POST',
    needToken: false,
    data: {
      tenantId: TENANT_ID,
      platformId: PLATFORM_ID,
      phonenumber,
      smsCode,
      clientId: CLIENT_ID,
      grantType: 'fulfiller_sms' // 使用履约者专用认证策略
    }
  })
}

/**
 * 发送短信验证码
 * @param {string} phonenumber - 手机号
 */
export function sendSmsCode(phonenumber) {
  return request({
    url: '/resource/sms/code',
    method: 'GET',
    needToken: false,
    data: { phonenumber }
  })
}

/**
 * 退出登录
 */
export function logout() {
  return request({
    url: '/auth/logout',
    method: 'POST'
  })
}

/**
 * 获取当前登录履约者信息
 */
export function getUserInfo() {
  return request({
    url: '/fulfiller/fulfiller/my',
    method: 'GET'
  })
}
