export const IntegrationErrorCode = {
  OAUTH_NOT_CONFIGURED: 'OAUTH_NOT_CONFIGURED',
  NO_INTEGRATION: 'NO_INTEGRATION',
  TOKEN_MISSING: 'TOKEN_MISSING',
  TOKEN_DECRYPT_FAILED: 'TOKEN_DECRYPT_FAILED',
  TOKEN_EXPIRED: 'TOKEN_EXPIRED',
  TOKEN_REFRESH_FAILED: 'TOKEN_REFRESH_FAILED',
  API_CONNECTION_FAILED: 'API_CONNECTION_FAILED',
} as const;

export type IntegrationErrorCodeType =
  (typeof IntegrationErrorCode)[keyof typeof IntegrationErrorCode];

export interface IntegrationStatus {
  type: string;
  configured: boolean;
  connected: boolean;
  tokensValid: boolean;
  canConnect: boolean;
  needsReconnect: boolean;
  lastSyncAt?: string;
  tokenExpiry?: string;
  errorCode?: IntegrationErrorCodeType;
  errorMessage?: string;
}

export const SyncErrorCode = {
  NO_INTEGRATION: 'NO_INTEGRATION',
  INTEGRATION_NOT_CONNECTED: 'INTEGRATION_NOT_CONNECTED',
  OAUTH_NOT_CONFIGURED: 'OAUTH_NOT_CONFIGURED',
  TOKEN_EXPIRED: 'TOKEN_EXPIRED',
  TOKEN_REFRESH_FAILED: 'TOKEN_REFRESH_FAILED',
  NO_CALENDARS_FOUND: 'NO_CALENDARS_FOUND',
  API_ERROR: 'API_ERROR',
  UNKNOWN_ERROR: 'UNKNOWN_ERROR',
} as const;

export type SyncErrorCodeType =
  (typeof SyncErrorCode)[keyof typeof SyncErrorCode];

export interface SyncErrorResponse {
  error: string;
  errorCode: SyncErrorCodeType;
  message?: string;
  needsReconnect?: boolean;
}
