/**
 * 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 = {
  // default entry is keyed with MASTER_SETTINGS_KEY; other entries are linked to an account with account ID
  id?: number; // this is erased for all those entries that are keyed with accountDid

  // if supplied, this settings record overrides the master record when the user switches to this account
  accountDid?: string; // not used in the MASTER_SETTINGS_KEY entry
  // active Decentralized ID
  activeDid?: string; // only used in the MASTER_SETTINGS_KEY entry

  apiServer?: string; // API server URL

  filterFeedByNearby?: boolean; // filter by nearby
  filterFeedByVisible?: boolean; // filter by visible users ie. anyone not hidden
  finishedOnboarding?: boolean; // the user has completed the onboarding process

  firstName?: string; // user's full name, may be null if unwanted for a particular account
  hideRegisterPromptOnNewContact?: boolean;
  isRegistered?: boolean;
  // imageServer?: string; // if we want to allow modification then we should make image functionality optional -- or at least customizable
  lastName?: string; // deprecated - put all names in firstName

  lastAckedOfferToUserJwtId?: string; // the last JWT ID for offer-to-user that they've acknowledged seeing
  lastAckedOfferToUserProjectsJwtId?: string; // the last JWT ID for offers-to-user's-projects that they've acknowledged seeing

  // The claim list has a most recent one used in notifications that's separate from the last viewed
  lastNotifiedClaimId?: string;
  lastViewedClaimId?: string;

  notifyingNewActivityTime?: string; // set to their chosen time if they have turned on daily check for new activity via the push server
  notifyingReminderMessage?: string; // set to their chosen message for a daily reminder
  notifyingReminderTime?: string; // set to their chosen time for a daily reminder

  partnerApiServer?: string; // partner server API URL

  passkeyExpirationMinutes?: number; // passkey access token time-to-live in minutes

  profileImageUrl?: string; // may be null if unwanted for a particular account

  // 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
};

// type of settings where the searchBoxes are JSON strings instead of objects
export type SettingsWithJsonStrings = Settings & {
  searchBoxes: string;
};

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

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

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

export const DEFAULT_PASSKEY_EXPIRATION_MINUTES = 15;
