"use server";
import { fetchData, fetchDataWithToken } from "../api-fetcher";
import { baseUrl, FilterList, FilterListInterface } from "../basics";

const livingSpaceListEndpoint = `${baseUrl}/building/living_space/list`;
const livingSpaceCreateEndpoint = `${baseUrl}/building/living_space/create`;
const livingSpaceUpdateEndpoint = `${baseUrl}/building/living_space/update`;

async function retrievelivingSpaceList(payload: FilterListInterface) {
  const feedObject = new FilterList(payload).filter();
  const tokenResponse: any = await fetchDataWithToken(
    livingSpaceListEndpoint,
    feedObject,
    "POST",
    false
  );
  return tokenResponse;
}

async function createLivingSpace(payload: any) {
  const tokenResponse: any = await fetchDataWithToken(
    livingSpaceCreateEndpoint,
    payload,
    "POST",
    true
  );
  return tokenResponse;
}

async function updateLivingSpace(payload: any) {
  const tokenResponse: any = await fetchDataWithToken(
    livingSpaceUpdateEndpoint,
    payload,
    "POST",
    true
  );
  return tokenResponse;
}

export { retrievelivingSpaceList, createLivingSpace, updateLivingSpace };
