import axios from 'axios';

const API_BASE_URL = 'http://localhost:8000/api/v1/dashboard';

export const fetchOverviewData = async () => {
  try {
    const response = await axios.get(`${API_BASE_URL}/overview`);
    return response.data;
  } catch (error) {
    console.error('Error fetching overview data:', error);
    return {};
  }
};

export const fetchRealtimeData = async () => {
  try {
    const response = await axios.get(`${API_BASE_URL}/realtime`);
    return response.data;
  } catch (error) {
    console.error('Error fetching realtime data:', error);
    return {};
  }
};

export const fetchFarmData = async () => {
  try {
    const response = await axios.get(`${API_BASE_URL}/farm`);
    return response.data;
  } catch (error) {
    console.error('Error fetching farm data:', error);
    return [];
  }
};

export const fetchGovernmentData = async (type) => {
  try {
    const response = await axios.get(`${API_BASE_URL}/government/${type}`);
    return response.data;
  } catch (error) {
    console.error('Error fetching government data:', error);
    return [];
  }
};

export const fetchFinanceData = async (type) => {
  try {
    const response = await axios.get(`${API_BASE_URL}/finance/${type}`);
    return response.data;
  } catch (error) {
    console.error('Error fetching finance data:', error);
    return [];
  }
};

export const fetchMapData = async () => {
  try {
    const response = await axios.get(`${API_BASE_URL}/map/regions`);
    return response.data;
  } catch (error) {
    console.error('Error fetching map data:', error);
    return [];
  }
};

export const fetchRegionDetail = async (regionId) => {
  try {
    const response = await axios.get(`${API_BASE_URL}/map/region/${regionId}`);
    return response.data;
  } catch (error) {
    console.error('Error fetching region detail:', error);
    return {};
  }
};