import { Color } from "@ionic/core";
import { Feed, Job, Location, Pin, Service, Site, Template, User } from "./sdk";

export interface WhereStatement {
  key?: string;
  conditional?: WhereFilterOp;
  value?: any;
}

export declare type WhereFilterOp =
  | "<"
  | "<="
  | "=="
  | "!="
  | ">="
  | ">"
  | "array-contains"
  | "in"
  | "array-contains-any"
  | "not-in";

export interface QueryFilters {
  query?: string;
  tags?: string[];
  limit?: number;
  orderBy?: string;
  orderDirection?: "asc" | "desc";
  whereEqual?: any;
  whereLessThan?: any;
  whereLessThanOrEqual?: any;
  whereGreaterThan?: any;
  whereGreaterThanOrEqual?: any;
  whereArrayContains?: any;
  whereArrayContainsAny?: any;
  whereIn?: any;
}

export interface TriggerPayload {
  queries?: {
    collection: string;
    aliasAs?: string;
    filter?: QueryFilters;
  }[];
  action?: "alert";
  payload?: any;
}

export interface Control {
  /**
   * The label to show next to the button
   */
  label: string;
  /**
   * The icon to use in the button
   */
  icon: string;
  /**
   * The color from the theme to make the button
   */
  color?: Color;
  /**
   * The link to use for the button
   */
  href?: string;
  /**
   * The functionality to run when the button is clicked
   */
  onClick?: (event: any) => any;
}

export interface LocalCache {
  colors: {
    primary: string;
    "primary-rgb": string;
    "primary-contrast": string;
    "primary-contrast-rgb": string;
    "primary-shade": string;
    "primary-tint": string;
    secondary: string;
    "secondary-rgb": string;
    "secondary-contrast": string;
    "secondary-contrast-rgb": string;
    "secondary-shade": string;
    "secondary-tint": string;
    tertiary: string;
    "tertiary-rgb": string;
    "tertiary-contrast": string;
    "tertiary-contrast-rgb": string;
    "tertiary-shade": string;
    "tertiary-tint": string;
    success: string;
    "success-rgb": string;
    "success-contrast": string;
    "success-contrast-rgb": string;
    "success-shade": string;
    "success-tint": string;
    warning: string;
    "warning-rgb": string;
    "warning-contrast": string;
    "warning-contrast-rgb": string;
    "warning-shade": string;
    "warning-tint": string;
    danger: string;
    "danger-rgb": string;
    "danger-contrast": string;
    "danger-contrast-rgb": string;
    "danger-shade": string;
    "danger-tint": string;
    dark: string;
    "dark-rgb": string;
    "dark-contrast": string;
    "dark-contrast-rgb": string;
    "dark-shade": string;
    "dark-tint": string;
    medium: string;
    "medium-rgb": string;
    "medium-contrast": string;
    "medium-contrast-rgb": string;
    "medium-shade": string;
    "medium-tint": string;
    light: string;
    "light-rgb": string;
    "light-contrast": string;
    "light-contrast-rgb": string;
    "light-shade": string;
    "light-tint": string;
  };
  darkMode?: boolean;
  helpers?: any;
  navigationView?: "menu" | "pins" | "feed" | "profile";
  manifest?: {
    name?: string;
    short_name?: string;
    start_url?: string;
    display?: string;
    icons?: {
      src?: string;
      sizes?: string;
      type?: string;
      purpose?: string;
    }[];
    shortcuts?: {
      name?: string;
      short_name?: string;
      description?: string;
      url?: string;
      icons?: {
        src?: string;
        sizes?: string;
      }[];
    }[];
    orientation?: string;
    background_color?: string;
    theme_color?: string;
    permissions?: string[];
    gcm_sender_id?: string;
    version?: string;
  };
  config?: {
    emulate?: boolean;
    env?: string;
    dade?: {
      apiKey?: string;
      url?: string;
    };
    functions?: {
      url?: string;
    };
    logrocketKey?: string;
    firebase?: {
      apiKey: string;
      authDomain: string;
      databaseURL: string;
      projectId: string;
      storageBucket: string;
      messagingSenderId: string;
      appId: string;
    };
    messaging?: {
      vapidKey?: string;
    };
    graphql?: {
      url?: string;
    };
    stripe?: {
      key?: string;
      clientId?: string;
    };
    franchise?: {
      stripe?: {
        key?: string;
        clientId?: string;
      };
      dade?: {
        apiKey?: string;
        url?: string;
      };
    };
    url?: string;
    dynamicLinkDomain?: string;
    showingNotifications?: boolean;
    algolia?: {
      appId?: string;
      searchKey?: string;
    };
  };
  locations?: Location[];
  profile?: User;
  session?: {
    displayName?: string | null;
    email?: string | null;
    phoneNumber?: string | null;
    photoURL?: string | null;
    providerId?: string;
    uid?: string;
    [key: string]: any;
  };
  services?: Service[];
  templates?: Template[];
  claims?: {
    admin?: boolean;
    tester?: boolean;
    role?: string;
    locationId?: string;
  };
  jobs?: { [jobId: string]: Job };
  job?: Job;
  site?: Site;
  pins?: Pin[];
  editorSizes?: number[];
  isPreviewing?: boolean;
  paymentMethods?: PaymentMethod[];
  showingNavigation?: boolean;
  roles?: string[];
  filters?: {
    [path: string]: {
      [filterName: string]: any;
    };
  };
  users?: { [userId: string]: User };
  user?: User;
}

export interface PaymentMethod {
  brand?: string;
  expirationMonth?: number;
  expirationYear?: number;
  id?: string;
  last4?: string;
  name?: string;
  type?: string;
}

export type InvoiceType =
  | "mitigation"
  | "mold"
  | "content"
  | "reconstruction"
  | "drain";
