import type { APP_CONSTANTS } from "../constants/app";

export default function(){

  const recipientList: { title: string, value: typeof APP_CONSTANTS[keyof typeof APP_CONSTANTS] }[] = [
    { title: "Security Agency", value: "security_agency" },
    { title: "Cleaning Services", value: "cleaning_services" },
    { title: "Mechanical & Electrical", value: "mechanical_electrical" },
    { title: "Property Management Agency", value: "property_management_agency" },
    { title: "Resident", value: "resident" },
    { title: "Pest Control", value: "pest_control_services" },
    { title: "Landscaping", value: "landscaping_services" },
    { title: "Pool Maintenance", value: "pool_maintenance_services" },

]

  async function add(payload: Partial<TCreateAnnouncementPayload>) {
    return await useNuxtApp().$api<Record<string, any>>("/api/bulletin-boards", {
      method: "POST",
      body: payload,
    });
  }

    async function update(bulletinId: string, payload: Partial<TCreateAnnouncementPayload>) {
    return await useNuxtApp().$api<Record<string, any>>(`/api/bulletin-boards/id/${bulletinId}`, {
      method: "PUT",
      body: payload,
    });
  }

    type TGetAllParams = {
    page?: number; 
    limit?: number; 
    order?: 'asc' | 'desc'; 
    site?: string;
    status?: TAnnouncementStatus;
    search?: string;
    recipients?: TAnnouncementRecipients;
  }

    async function getAll({
    page = 1,
    limit = 10,
    order = "desc",
    site,
    status,
    search,
    recipients
  } : TGetAllParams) {
    return await useNuxtApp().$api<Record<string, any>>(
      "/api/bulletin-boards",
      {
        method: "GET",
        query: {
          page,
          limit,
          order,
          site,
          status,
          search,
          recipients
        },
      }
    );
  }

  async function getBulletinById(bulletinId: string) {
    return await useNuxtApp().$api<Record<string, any>>(`/api/bulletin-boards/id/${bulletinId}`, {
      method: "GET",
    });
  }

    async function deleteBulletinById(bulletinId: string) {
    return await useNuxtApp().$api<Record<string, any>>(`/api/bulletin-boards/${bulletinId}`, {
      method: "PUT",
    });
  }


    return {
      recipientList,
        add,
        update,
        getAll,
        getBulletinById,
        deleteBulletinById
        
    }
}