import service from '../service';
import type {
  UserListParams,
  UserListItem,
  UserListParamsV2,
  UserInfo,
  StaffsInfo,
  PayInfo,
  StaffQuery
} from './data.d';


//查询用户列表
export async function queryUserList(params: UserListParamsV2) {

  // params.current = Number(params.current)
  // params.current = params.current ? params.current - 1 : params.current
  console.log(params)
  let result = await service.post('/api/v1/platform/list/user', {
    "user_name": params.user_name,
    "page_no": params.current,
    "page_size": params.pageSize
  });

  return Promise.resolve({
    data: result.data.users,
    success: true,
  })
}

//查询用户列表
export async function queryStaffList(params: StaffQuery) {

  // params.current = Number(params.current)
  // params.current = params.current ? params.current - 1 : params.current
  let page_no = params.page_no || 0
  let page_size = params.page_size || 100
  console.log(params)

  let result = await service.post('/api/v1/customer/list/staff', {
    id: params.id,
    name: params.name,
    serial_no: params.serial_no,
    page_no: page_no,
    page_size: page_size,

  });

  return Promise.resolve({
    data: result.data,
    success: true,
  })
}

export async function queryProductionList() {

  // params.current = Number(params.current)
  // params.current = params.current ? params.current - 1 : params.current
  let result = await service.post('/api/v1/customer/list/production', {
    // "user_name": params.user_name,
    // "page_no": params.current,
    // "page_size": params.pageSize
  });

  return Promise.resolve({
    data: result.data,
    success: true,
  })
}


//删除用户
export async function removeUser(params: { user_name: string[] }) {
  let result = await service.post('/api/v1/platform/delete/user', {
    user_name: params.user_name[0],
  });

  return Promise.resolve({
    data: result.data,
    success: true,
  })
}

//添加员工
export async function addStaff(params: StaffsInfo) {
  let result = await service.post('/api/v1/customer/create/staff', {
    name: params.name,
    org_name: params.org_name,
    tone: params.tone,
    output_length: params.output_length,
    description: params.description,
    avatar_url: params.avatar_url,
  });

  return Promise.resolve({
    data: result.data,
    success: true,
  })
}

//更新用户
export async function updateUser(params: UserInfo) {
  let result = await service.post('/api/v1/platform/edit/user', {
    user_name: params.user_name,
    user_alias: params.user_alias,
    phone_number: params.phone_number,
    password: params.password,
    remark: params.remark,
    role_name: params.role_name,
  });

  return Promise.resolve({
    data: result.data,
    success: true,
  })
}

//更新用户
export async function payStaff(params: PayInfo) {
  let result = await service.post('/api/v1/customer/pay/staff', {
    id: params.id,
    production_id: params.production_id,
    pay_type: params.pay_type,
  });

  return Promise.resolve({
    data: result.data,
    success: true,
  })
}


//查询支付状态
// "state": 0,          //订单状态(0=待支付 1=处理中 2=已成功支付 3=已取消 4=已退款 5=支付平台异常)
// "message": "Success" //订单交易状态信息
export async function queryPayStatus(trade_no: string) {
  let result = await service.post('/api/v1/customer/query/trade', {
    trade_no: trade_no,
  });

  return Promise.resolve({
    data: result.data,
    success: true,
  })
}

