import { get, put } from '../utils/request'

// 获取当前月份的预算信息（包含统计数据）
export async function getBudget() {
  try {
    const response = await get('/budgets')
    return response
  } catch (error) {
    console.error('获取预算信息失败:', error)
    throw error
  }
}

// 获取上月预算结算信息
export async function getBudgetSettlement() {
  try {
    const response = await get('/budgets/settlement')
    return response
  } catch (error) {
    console.error('获取预算结算信息失败:', error)
    throw error
  }
}

// 设置预算
export async function setBudget(data) {
  try {
    const now = new Date()
    const requestData = {
      year: data.year || now.getFullYear(),
      month: data.month || (now.getMonth() + 1),
      amount: data.amount
    }

    const response = await put('/budgets', requestData)
    return response
  } catch (error) {
    console.error('设置预算失败:', error)
    throw error
  }
}


