// API Version
export const API_VERSION = 'v1'

// API Base URL
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL

// API Endpoints
export const API_ENDPOINTS = {
  // Auth
  AUTH: {
    LOGIN: '/auth/jwt/login',
    GUEST: '/auth/guest',
    SIGNUP: '/auth/register',
    LOGOUT: '/auth/jwt/logout',
    REFRESH: '/auth/jwt/refresh',
    VERIFY_EMAIL: '/auth/verify',
    RESET_PASSWORD: '/auth/forgot-password',
    FORGOT_PASSWORD: '/auth/forgot-password',
    MAGIC_LINK: '/auth/magic-link',
    MAGIC_LINK_VERIFY: '/auth/magic-link/verify',
  },

  // Users
  USERS: {
    PROFILE: '/users/me',
    UPDATE_PROFILE: '/users/me',
    PASSWORD: '/users/password',
    AVATAR: '/users/avatar',
    SETTINGS: '/users/settings',
    NOTIFICATIONS: '/users/notifications',
    PREFERENCES: '/users/preferences',
  },

  // Lists
  LISTS: {
    BASE: '/lists',
    BY_ID: (id: string) => `/lists/${id}`,
    STATUS: (id: string) => `/lists/${id}/status`,
    STATUSES: '/lists/statuses',
    ITEMS: (listId: string) => `/lists/${listId}/items`,
    ITEM: (listId: string, itemId: string) => `/lists/${listId}/items/${itemId}`,
    EXPENSES: (listId: string) => `/lists/${listId}/expenses`,
    SHARE: (listId: string) => `/lists/${listId}/share`,
    UNSHARE: (listId: string) => `/lists/${listId}/unshare`,
    COMPLETE: (listId: string) => `/lists/${listId}/complete`,
    REOPEN: (listId: string) => `/lists/${listId}/reopen`,
    ARCHIVE: (listId: string) => `/lists/${listId}/archive`,
    UNARCHIVE: (listId: string) => `/lists/${listId}/unarchive`,
    DUPLICATE: (listId: string) => `/lists/${listId}/duplicate`,
    EXPORT: (listId: string) => `/lists/${listId}/export`,
    IMPORT: '/lists/import',
    ARCHIVED: '/lists/archived',
  },

  CATEGORIES: {
    BASE: '/categories',
    BY_ID: (id: string) => `/categories/${id}`,
  },

  // Groups
  GROUPS: {
    BASE: '/groups',
    BY_ID: (id: string) => `/groups/${id}`,
    LISTS: (groupId: string) => `/groups/${groupId}/lists`,
    MEMBERS: (groupId: string) => `/groups/${groupId}/members`,
    MEMBER: (groupId: string, userId: string) => `/groups/${groupId}/members/${userId}`,
    CREATE_INVITE: (groupId: string) => `/groups/${groupId}/invites`,
    GET_ACTIVE_INVITE: (groupId: string) => `/groups/${groupId}/invites`,
    REVOKE_INVITE: (groupId: string, code: string) => `/groups/${groupId}/invites/${code}`,
    LEAVE: (groupId: string) => `/groups/${groupId}/leave`,
    DELETE: (groupId: string) => `/groups/${groupId}`,
    SETTINGS: (groupId: string) => `/groups/${groupId}/settings`,
    ROLES: (groupId: string) => `/groups/${groupId}/roles`,
    ROLE: (groupId: string, roleId: string) => `/groups/${groupId}/roles/${roleId}`,
    GENERATE_SCHEDULE: (groupId: string) => `/groups/${groupId}/chores/generate-schedule`,
    CHORE_HISTORY: (groupId: string) => `/groups/${groupId}/chores/history`,
  },

  // Activity
  ACTIVITY: {
    GET_BY_GROUP: (groupId: number) => `/groups/${groupId}/activity`,
  },

  // Invites
  INVITES: {
    BASE: '/invites',
    BY_ID: (id: string) => `/invites/${id}`,
    ACCEPT: (id: string) => `/invites/accept/${id}`,
    DECLINE: (id: string) => `/invites/decline/${id}`,
    REVOKE: (id: string) => `/invites/revoke/${id}`,
    LIST: '/invites',
    PENDING: '/invites/pending',
    SENT: '/invites/sent',
  },

  // Items (for direct operations like update, get by ID)
  ITEMS: {
    BY_ID: (itemId: string) => `/items/${itemId}`,
  },

  // OCR
  OCR: {
    PROCESS: '/ocr/extract-items',
    STATUS: (jobId: string) => `/ocr/status/${jobId}`,
    RESULT: (jobId: string) => `/ocr/result/${jobId}`,
    BATCH: '/ocr/batch',
    CANCEL: (jobId: string) => `/ocr/cancel/${jobId}`,
    HISTORY: '/ocr/history',
  },

  // Costs
  COSTS: {
    BASE: '/costs',
    LIST_SUMMARY: (listId: string | number) => `/costs/lists/${listId}/cost-summary`,
    GROUP_BALANCE_SUMMARY: (groupId: string | number) => `/costs/groups/${groupId}/balance-summary`,
  },

  // Financials
  FINANCIALS: {
    EXPENSES: '/financials/expenses',
    EXPENSE: (id: string) => `/financials/expenses/${id}`,
    SETTLEMENTS: '/financials/settlements',
    SETTLEMENT: (id: string) => `/financials/settlements/${id}`,
    BALANCES: '/financials/balances',
    BALANCE: (userId: string) => `/financials/balances/${userId}`,
    REPORTS: '/financials/reports',
    REPORT: (id: string) => `/financials/reports/${id}`,
    CATEGORIES: '/financials/categories',
    CATEGORY: (id: string) => `/financials/categories/${id}`,
    USER_SUMMARY: '/financials/summary/user',
    GROUP_SUMMARY: (groupId: string) => `/financials/summary/group/${groupId}`,
  },

  // Health
  HEALTH: {
    CHECK: '/health',
    VERSION: '/health/version',
    STATUS: '/health/status',
    METRICS: '/health/metrics',
    LOGS: '/health/logs',
  },

  CHORES: {
    // Generic
    ALL: '/chores/all',
    BASE: '/chores',
    BY_ID: (id: number) => `/chores/${id}`,
    UPDATE_ANY_TYPE: (id: number) => `/chores/${id}`,
    HISTORY: (id: number) => `/chores/${id}/history`,
    ASSIGNMENTS: (choreId: number) => `/chores/${choreId}/assignments`,

    // Personal chore shortcuts
    PERSONAL: '/chores/personal',
    PERSONAL_BY_ID: (id: number) => `/chores/personal/${id}`,

    // Group chore shortcuts
    GROUP_CHORES: (groupId: number) => `/chores/groups/${groupId}/chores`,
    GROUP_CHORE_BY_ID: (groupId: number, choreId: number) => `/chores/groups/${groupId}/chores/${choreId}`,

    // Assignment centric paths
    ASSIGNMENTS_BASE: '/chores/assignments',
    ASSIGNMENT_BY_ID: (id: number) => `/chores/assignments/${id}`,
    MY_ASSIGNMENTS: (includeCompleted: boolean) => `/chores/assignments/my?include_completed=${includeCompleted}`,
    ASSIGNMENT_COMPLETE: (id: number) => `/chores/assignments/${id}/complete`,

    // Time tracking
    TIME_ENTRIES: (assignmentId: number) => `/chores/assignments/${assignmentId}/time-entries`,
    TIME_ENTRY: (id: number) => `/chores/time-entries/${id}`,
  },
}
