/**
 * BoundingBox type describes the geographical bounding box coordinates.
 */
export type BoundingBox = {
  eastLong: number; // Eastern longitude
  maxLat: number; // Maximum (Northernmost) latitude
  minLat: number; // Minimum (Southernmost) latitude
  westLong: number; // Western longitude
};

/**
 * Settings type encompasses user-specific configuration details.
 */
export type Settings = {
  id: number; // Only one entry, keyed with MASTER_SETTINGS_KEY

  activeDid?: string; // Active Decentralized ID
  apiServer?: string; // API server URL

  filterFeedByNearby?: boolean; // filter by nearby
  filterFeedByVisible?: boolean; // filter by visible users ie. anyone not hidden

  firstName?: string; // user's full name
  hideRegisterPromptOnNewContact?: boolean;
  isRegistered?: boolean;
  lastName?: string; // deprecated - put all names in firstName
  lastNotifiedClaimId?: string;
  lastViewedClaimId?: string;
  profileImageUrl?: string;
  reminderTime?: number; // Time in milliseconds since UNIX epoch for reminders
  reminderOn?: boolean; // Toggle to enable or disable reminders

  // Array of named search boxes defined by bounding boxes
  searchBoxes?: Array<{
    name: string;
    bbox: BoundingBox;
  }>;

  showContactGivesInline?: boolean; // Display contact inline or not
  showGeneralAdvanced?: boolean; // Show advanced features which don't have their own flag
  showShortcutBvc?: boolean; // Show shortcut for Bountiful Voluntaryist Community actions
  vapid?: string; // VAPID (Voluntary Application Server Identification) field for web push
  warnIfProdServer?: boolean; // Warn if using a production server
  warnIfTestServer?: boolean; // Warn if using a testing server
  webPushServer?: string; // Web Push server URL
};

export function isAnyFeedFilterOn(settings: Settings): boolean {
  return !!(settings.filterFeedByNearby || settings.filterFeedByVisible);
}

/**
 * Schema for the Settings table in the database.
 */
export const SettingsSchema = {
  settings: "id",
};

/**
 * Constants.
 */
export const MASTER_SETTINGS_KEY = 1;
