/**
 * 认证相关 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: {
      userSource: 1,
      username,
      password,
      clientId: CLIENT_ID,
      grantType: 'password',
      source: 1
    }
  })
}

/**
 * 短信验证码登录
 * @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' // 使用履约者专用认证策略
    }
  })
}

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