/**
 * Directus API Service for kashilo.com — Facade
 * Re-exports modular sub-services as a single backward-compatible singleton.
 * @module services/directus
 */

import { client, DirectusError } from './directus/client.js'
import * as authApi from './directus/auth.js'
import * as listingsApi from './directus/listings.js'
import * as categoriesApi from './directus/categories.js'
import * as locationsApi from './directus/locations.js'
import * as conversationsApi from './directus/conversations.js'
import * as filesApi from './directus/files.js'
import * as notificationsApi from './directus/notifications.js'

const directus = {
    // ── Client / Token ──
    get baseUrl() { return client.baseUrl },
    get accessToken() { return client.accessToken },
    isAuthenticated: () => client.isAuthenticated(),
    clearTokens: () => client.clearTokens(),

    // ── Generic HTTP (used by external services like favorites) ──
    get: (endpoint, params) => client.get(endpoint, params),
    post: (endpoint, data) => client.post(endpoint, data),
    patch: (endpoint, data) => client.patch(endpoint, data),
    delete: (endpoint) => client.delete(endpoint),

    // ── Auth ──
    login: authApi.login,
    logout: authApi.logout,
    register: authApi.register,
    requestPasswordReset: authApi.requestPasswordReset,
    resetPassword: authApi.resetPassword,
    getCurrentUser: authApi.getCurrentUser,
    updateCurrentUser: authApi.updateCurrentUser,

    // ── Listings ──
    getListings: listingsApi.getListings,
    getListing: listingsApi.getListing,
    createListing: listingsApi.createListing,
    updateListing: listingsApi.updateListing,
    incrementListingViews: listingsApi.incrementListingViews,
    deleteListing: listingsApi.deleteListing,
    getMyListings: listingsApi.getMyListings,
    searchListings: listingsApi.searchListings,
    getListingsByCategory: listingsApi.getListingsByCategory,
    getListingsByLocation: listingsApi.getListingsByLocation,

    // ── Categories ──
    getCategories: categoriesApi.getCategories,
    getCategory: categoriesApi.getCategory,
    getCategoryTree: categoriesApi.getCategoryTree,
    buildCategoryTree: categoriesApi.buildCategoryTree,
    getSubcategories: categoriesApi.getSubcategories,

    // ── Locations ──
    getLocations: locationsApi.getLocations,
    getLocation: locationsApi.getLocation,
    searchLocations: locationsApi.searchLocations,
    getLocationsByRegion: locationsApi.getLocationsByRegion,
    getLocationsByCountry: locationsApi.getLocationsByCountry,

    // ── Conversations ──
    getConversations: conversationsApi.getConversations,
    getConversation: conversationsApi.getConversation,
    getConversationMessages: conversationsApi.getConversationMessages,
    sendMessage: conversationsApi.sendMessage,
    startConversation: conversationsApi.startConversation,
    findConversation: conversationsApi.findConversation,
    updateConversationStatus: conversationsApi.updateConversationStatus,

    // ── Files ──
    uploadFile: filesApi.uploadFile,
    uploadMultipleFiles: filesApi.uploadMultipleFiles,
    getFileUrl: filesApi.getFileUrl,
    getThumbnailUrl: filesApi.getThumbnailUrl,

    // ── Notifications ──
    getNotifications: notificationsApi.getNotifications,
    getUnreadCount: notificationsApi.getUnreadCount,
    markNotificationRead: notificationsApi.markNotificationRead,
    markAllNotificationsRead: notificationsApi.markAllNotificationsRead,
    deleteNotification: notificationsApi.deleteNotification
}

export { directus, DirectusError }
