import type { EntityNameItem } from "../../../common/entity/compute_entity_name_display";
import type { ActionConfig } from "../../../data/lovelace/config/action";
import type { LovelaceBadgeConfig } from "../../../data/lovelace/config/badge";
import type { LegacyStateFilter } from "../common/evaluate-filter";
import type { Condition } from "../common/validate-condition";
import type { EntityFilterEntityConfig } from "../entity-rows/types";
import type { DisplayType } from "./hui-entity-badge";
import type { TimestampRenderingFormat } from "../components/types";

export interface EntityFilterBadgeConfig extends LovelaceBadgeConfig {
  type: "entity-filter";
  entities: (EntityFilterEntityConfig | string)[];
  state_filter?: LegacyStateFilter[];
  conditions?: Condition[];
}

export interface ErrorBadgeConfig extends LovelaceBadgeConfig {
  error: string;
  origConfig: LovelaceBadgeConfig;
}

export interface StateLabelBadgeConfig extends LovelaceBadgeConfig {
  entity: string;
  name?: string;
  icon?: string;
  image?: string;
  color?: string;
  show_name?: boolean;
  tap_action?: ActionConfig;
  hold_action?: ActionConfig;
  double_tap_action?: ActionConfig;
}

export interface ShortcutBadgeConfig extends LovelaceBadgeConfig {
  text?: string;
  icon?: string;
  color?: string;
  tap_action?: ActionConfig;
  hold_action?: ActionConfig;
  double_tap_action?: ActionConfig;
}

export interface EntityBadgeConfig extends LovelaceBadgeConfig {
  type: "entity";
  entity?: string;
  name?: string | EntityNameItem | EntityNameItem[];
  icon?: string;
  color?: string;
  show_name?: boolean;
  show_state?: boolean;
  show_icon?: boolean;
  show_entity_picture?: boolean;
  state_content?: string | string[];
  tap_action?: ActionConfig;
  hold_action?: ActionConfig;
  double_tap_action?: ActionConfig;
  time_format?: TimestampRenderingFormat;
  /**
   * @deprecated use `show_state`, `show_name`, `icon_type`
   */
  display_type?: DisplayType;
}

interface EnergyTotalBadgeConfig extends LovelaceBadgeConfig {
  title?: string;
  collection_key?: string;
}

export interface PowerTotalBadgeConfig extends EnergyTotalBadgeConfig {
  type: "power-total";
}

export interface WaterTotalBadgeConfig extends EnergyTotalBadgeConfig {
  type: "water-total";
}

export interface GasTotalBadgeConfig extends EnergyTotalBadgeConfig {
  type: "gas-total";
}
