import request from '@/utils/request'
import { getCommunityId } from '@/api/community/communityApi'

// 获取车位申请列表
export function listParkingSpaceApply(params) {
  return new Promise((resolve, reject) => {
    params.communityId = getCommunityId()
    request({
      url: '/parkingSpaceApply.listParkingSpaceApply',
      method: 'get',
      params
    }).then(response => {
      const res = response.data
      if (res.code === 0) {
        resolve(res)
      } else {
        reject(new Error(res.msg || '获取车位申请列表失败'))
      }
    }).catch(error => {
      reject(error)
    })
  })
}

// 更新车位申请
export function updateParkingSpaceApply(data) {
  return new Promise((resolve, reject) => {
    data.communityId = getCommunityId()
    request({
      url: '/parkingSpaceApply.updateParkingSpaceApply',
      method: 'post',
      data
    }).then(response => {
      const res = response.data
      if (res.code === 0) {
        resolve(res)
      } else {
        reject(new Error(res.msg || '更新车位申请失败'))
      }
    }).catch(error => {
      reject(error)
    })
  })
}

// 删除车位申请
export function deleteParkingSpaceApply(data) {
  return new Promise((resolve, reject) => {
    data.communityId = getCommunityId()
    request({
      url: '/parkingSpaceApply.deleteParkingSpaceApply',
      method: 'post',
      data
    }).then(response => {
      const res = response.data
      if (res.code === 0) {
        resolve(res)
      } else {
        reject(new Error(res.msg || '删除车位申请失败'))
      }
    }).catch(error => {
      reject(error)
    })
  })
}