// ---------------------------------------------------------------------------
// RealProvider — DataProvider implementation that delegates to existing API modules
// ---------------------------------------------------------------------------

import type { DataProvider } from './data-provider';
import * as residencesApi from '@/lib/api/residences';
import * as tasksApi from '@/lib/api/tasks';
import * as contractorsApi from '@/lib/api/contractors';
import * as documentsApi from '@/lib/api/documents';
import * as lookupsApi from '@/lib/api/lookups';
import * as notificationsApi from '@/lib/api/notifications';
import * as subscriptionApi from '@/lib/api/subscription';
import * as authApi from '@/lib/api/auth';

export const realProvider: DataProvider = {
  basePath: '/app',

  residences: {
    list: () => residencesApi.listResidences(),
    get: (id) => residencesApi.getResidence(id),
    create: (data) => residencesApi.createResidence(data),
    update: (id, data) => residencesApi.updateResidence(id, data),
    delete: (id) => residencesApi.deleteResidence(id),
    getMyResidences: () => residencesApi.getMyResidences(),
    getSummary: () => residencesApi.getSummary(),
  },

  tasks: {
    list: (days) => tasksApi.listTasks(days),
    get: (id) => tasksApi.getTask(id),
    create: (data) => tasksApi.createTask(data),
    update: (id, data) => tasksApi.updateTask(id, data),
    delete: (id) => tasksApi.deleteTask(id),
    getByResidence: (residenceId, days) => tasksApi.getTasksByResidence(residenceId, days),
    getCompletions: (taskId) => tasksApi.getTaskCompletions(taskId),
    createCompletion: (data) => tasksApi.createCompletion(data),
    createCompletionWithImages: (data, images) => tasksApi.createCompletionWithImages(data, images),
    markInProgress: (id) => tasksApi.markInProgress(id),
    cancel: (id) => tasksApi.cancelTask(id),
    uncancel: (id) => tasksApi.uncancelTask(id),
    archive: (id) => tasksApi.archiveTask(id),
    unarchive: (id) => tasksApi.unarchiveTask(id),
    quickComplete: (id) => tasksApi.quickComplete(id),
  },

  contractors: {
    list: () => contractorsApi.listContractors(),
    get: (id) => contractorsApi.getContractor(id),
    create: (data) => contractorsApi.createContractor(data),
    update: (id, data) => contractorsApi.updateContractor(id, data),
    delete: (id) => contractorsApi.deleteContractor(id),
    toggleFavorite: (id) => contractorsApi.toggleFavorite(id),
    getTasks: (id) => contractorsApi.getContractorTasks(id),
  },

  documents: {
    list: (params) => documentsApi.listDocuments(params),
    listWarranties: () => documentsApi.listWarranties(),
    get: (id) => documentsApi.getDocument(id),
    create: (data) => documentsApi.createDocument(data),
    createWithFile: (data, file) => documentsApi.createDocumentWithFile(data, file),
    update: (id, data) => documentsApi.updateDocument(id, data),
    delete: (id) => documentsApi.deleteDocument(id),
  },

  lookups: {
    getStaticData: () => lookupsApi.getStaticData(),
  },

  sharing: {
    getShareCode: (residenceId) => residencesApi.getShareCode(residenceId),
    generateShareCode: (residenceId, data) => residencesApi.generateShareCode(residenceId, data),
    generateSharePackage: (residenceId, data) => residencesApi.generateSharePackage(residenceId, data),
    getResidenceUsers: (residenceId) => residencesApi.getResidenceUsers(residenceId),
    removeUser: (residenceId, userId) => residencesApi.removeResidenceUser(residenceId, userId),
    joinWithCode: (data) => residencesApi.joinWithCode(data),
    generateTasksReport: (residenceId, email) => residencesApi.generateTasksReport(residenceId, email),
  },

  notifications: {
    list: (limit, offset) => notificationsApi.listNotifications(limit, offset),
    getUnreadCount: () => notificationsApi.getUnreadCount(),
    getPreferences: () => notificationsApi.getPreferences(),
    updatePreferences: (data) => notificationsApi.updatePreferences(data),
    markAsRead: (id) => notificationsApi.markAsRead(id),
    markAllAsRead: () => notificationsApi.markAllAsRead(),
  },

  subscription: {
    getStatus: () => subscriptionApi.getSubscriptionStatus(),
    getFeatureBenefits: () => subscriptionApi.getFeatureBenefits(),
    getUpgradeTriggers: () => subscriptionApi.getAllUpgradeTriggers(),
  },

  auth: {
    getCurrentUser: () => authApi.getCurrentUser(),
    logout: () => authApi.logout(),
  },
};
