import type Map from "@arcgis/core/Map.js";
import type Graphic from "@arcgis/core/Graphic.js";
import type FeatureLayerView from "@arcgis/core/views/layers/FeatureLayerView.js";
import type FeatureLayer from "@arcgis/core/layers/FeatureLayer.js";
import type MapView from "@arcgis/core/views/MapView.js";
import type Extent from "@arcgis/core/geometry/Extent.js";
import type Geometry from "@arcgis/core/geometry/Geometry.js";
import type Point from "@arcgis/core/geometry/Point.js";
import type { UserSession } from "@esri/solution-common";
import type { MapPicker } from "../components/map-picker/customElement.js";
import type { MapLayerPicker } from "../components/map-layer-picker/customElement.js";
import type { IPagedResponse } from "@esri/arcgis-rest-types";
import type { SolutionDeployedCard } from "../components/solution-deployed-card/customElement.js";
import type { Controller } from "@arcgis/lumina/controllers";
import type { Auth } from "./Auth.js";
import type { Telemetry } from "@esri/telemetry";
import type { ScreenPoint } from "@arcgis/core/core/types.js";
import type { Icon as Icon } from "@esri/calcite-components/components/calcite-icon";

export type ELayoutMode = "GRID" | "HORIZONTAL" | "VERTICAL";

export type EPageType = "LIST" | "SELECT" | "EXPORT" | "REFINE";

export type ESegmentType = "STANDARD" | "CUSTOM";

export type ESelectionMode = "ADD" | "REMOVE";

export type ESelectionType = "POINT" | "LINE" | "POLY" | "RECT";

export type EWorkflowType = "SEARCH" | "SELECT" | "SKETCH" | "REFINE";

export type EExportType = "CSV" | "PDF";

export type EDrawMode = "SKETCH" | "REFINE";

export const BATCH_EDIT_LIMIT: 500;

export type DistanceUnit = "feet" | "meters" | "miles" | "kilometers";

export type theme = "light" | "dark";

export type ScopeType = "all-solutions" | "deployments";

export type TooltipPlacement = "auto" | "top" | "right" | "bottom" | "left" | "top-start" | "top-end" | "right-start" | "right-end" | "bottom-start" | "bottom-end" | "left-start" | "left-end" | "auto-start" | "auto-end" | "leading-start" | "leading" | "leading-end" | "trailing-end" | "trailing" | "trailing-start";

export interface IMapClick {
  mapPoint: Point;
  screenPoint: ScreenPoint;
  x: number;
  y: number;
  button: number;
  buttons: 0 | 1 | 2;
  type: string;
  stopPropagation: any;
  timestamp: number;
  native: PointerEvent;
}

export interface IDeleteIds {
  ids: number[];
}

export interface IRefineOperation {
  ids: number[];
  mode: ESelectionMode;
  layerView: FeatureLayerView;
}

export interface ISearchConfiguration {
  activeSourceIndex?: number;
  allPlaceholder?: string;
  includeDefaultSources?: boolean;
  searchAllEnabled?: boolean;
  sources?: Array<ILocatorSourceConfigItem | ILayerSourceConfigItem>;
}

export interface ISearchSourceConfigItem {
  maxResults: number;
  maxSuggestions: number;
  minSuggestCharacters: number;
  name: string;
  suggestionsEnabled: boolean;
  placeholder: string;
  withinViewEnabled: boolean;
  zoomScale: number;
  outFields?: string[];
}

export interface ILocatorSourceConfigItem extends ISearchSourceConfigItem {
  url?: string;
  singleLineFieldName: string;
  countryCode: string;
}

export interface ILayerSourceConfigItem extends ISearchSourceConfigItem {
  displayField: string;
  exactMatch: boolean;
  layer: {
      url: string | FeatureLayer;
      id: string;
  };
  outFields: string[];
  searchFields: string;
  popupTemplate: any;
  popupEnabled: boolean;
}

export interface IDropdownItem {
  displayValue: string;
  sortType: SortType;
}

export interface ISearchSortSettings extends ISearchOption, ISortOption {
  isOrgSolutions: boolean;
}

export interface IScopeSearchSortSettings {
  scope: ScopeType;
  settings: ISearchSortSettings;
}

export interface ISearchTerm {
  searchTerm: string;
  scope: ScopeType;
}

export interface ISortType {
  sortType: SortType;
  scope: ScopeType;
}

export interface IValueChange {
  oldValue: number | string;
  newValue: number | string;
}

/** Layer or table id and title key value pair */
export type IMapItemHash = { [key: string]: ILayerHashInfo; };

export interface ILayerHashInfo {
  name: string;
  supportsUpdate: boolean;
}

/** Stores the id, type, and title for a given template */
export interface ITemplateInfo {
  id: string;
  owner: string;
  title: string;
  type: string;
  typeKeywords: string[];
  snippet: string;
  url?: string;
}

export type ILayerItemsHash = { [key: string]: ILayerDetailsHash; };

export interface ILayerDetailsHash {
  name: string;
  formattedFeatureCount: string;
  supportsUpdate: boolean;
  supportsAdd: boolean;
}

/** A templates share details */
export interface ISearchConfig {
  layers: string[];
  layerUrl: string;
  locators: string[];
  locatorUrl: string;
}

export interface ISearchResult {
  graphics: Graphic[];
  name: string;
}

export interface ISelectionSet {
  id: number;
  searchResult: any;
  buffer?: Geometry;
  distance: number;
  download: boolean;
  unit: DistanceUnit;
  label: string;
  selectedIds: number[];
  layerView?: FeatureLayerView;
  geometries: Geometry[];
  graphics: Graphic[];
  selectLayers: FeatureLayerView[];
  skipGeomOIDs?: number[];
  workflowType: EWorkflowType;
  searchDistanceEnabled: boolean;
  useLayerFeaturesEnabled: boolean;
  refineInfos: IRefineInfo;
  redoStack?: IRefineOperation[];
  undoStack?: IRefineOperation[];
  sketchGraphic?: Graphic;
  undoGraphicsArr?: any[];
}

export type IRefineInfo = { [key: string]: IRefineIds; };

export interface IRefineIds {
  addIds: number[];
  removeIds: number[];
  layerView: FeatureLayerView;
}

export interface ISketchGraphicsChange {
  graphics: Graphic[];
  useOIDs: boolean;
}

export interface IQueryExtentResponse {
  count: number;
  extent: Extent | null;
}

export interface IBeforeLayerSelectionChange {
  currentId?: string;
  currentIds?: string[];
  newId?: string;
  newIds?: string[];
  ref: MapLayerPicker;
}

export interface IBeforeMapChange {
  currentId: string;
  mapInfo: IMapInfo;
  ref: MapPicker;
}

export interface IMapInfo {
  id: string;
  name: string;
  searchConfiguration?: ISearchConfiguration;
  filterConfig?: IFilterConfig;
  _hasValidLayers?: boolean;
  visible?: boolean;
  layerOptions?: ILayerOptions;
  enableInlineEdit: boolean;
  enableCreateFeatures: boolean;
  createFeatureButtonLabel: string;
  enableEditGeometry: boolean;
  enableTableAutosave: boolean;
}

export interface ILayerOptions {
  layers: ILayerDef[];
  mapId?: string;
  configLayerOrder?: string[];
}

export interface ILayerDef {
  id: string;
  sublayerId?: number;
  fields?: string[];
  extraFields: string[];
  fieldOrder?: string[];
  sortField?: string;
  sortOrder?: "asc" | "desc";
}

export interface IMapChange {
  id: string;
  mapView?: MapView;
  isValid: boolean;
}

export type IExportInfos = { [key: string]: IExportInfo; };

export interface IExportInfo {
  ids: number[];
  layer?: FeatureLayer;
  layerView?: FeatureLayerView;
  selectionSetNames: string[];
}

export interface IBasemapConfig {
  basemapIdsToFilter: string[];
  basemapGroupId: string;
}

export interface IToolInfo {
  active: boolean;
  icon: Icon["icon"];
  indicator: boolean;
  func: any;
  label: string;
  toolTip: string;
  disabled: boolean;
  isDanger?: boolean;
  loading?: boolean;
}

export type IColumnsInfo = { [key: string]: boolean; };

export interface IFilterConfig {
  mapId: string;
  layerExpressions: ILayerExpression[];
}

export interface ILayerExpression {
  id: string;
  sublayerId: number;
  title: string;
  expressions: IExpression[];
  operator: string;
}

export interface IImageExtraction {
  field: string;
  id: string;
  prompt: string;
}

export interface ITextExtraction {
  field: string;
  id: string;
  prompt: string;
  extractLocation?: boolean;
}

export interface ISortFields {
  layers: ISortFieldsLayer[];
}

export interface ISortFieldsLayer {
  id: string;
  fields: string[];
  fieldOrder: string[];
}

export type ExpressionField = "string" | "number" | "date" | "coded-value" | "range" | "checkbox";

export type EditType = "update" | "add" | "delete";

export type ButtonType = "button" | "action";

export type AppLayout = "mapView" | "tableView" | "splitView";

export type VisibilityIconType = "checkbox" | "eyeball";

export interface IExpression {
  id: number;
  type?: ExpressionField;
  active?: boolean;
  definitionExpression?: string;
  name: string;
  field?: string;
  fields?: string[] | number[];
  selectedFields?: string[] | number[];
  codedValues?: { [key: string]: string; };
  placeholder?: string;
  min?: number | string;
  max?: number | string;
  range?: {
      min: string | number | undefined;
      max: string | number | undefined;
  };
  step?: number;
  numDisplayOption?: "slider" | "drop-down";
}

export interface ILayerAndTableIds {
  layerIds: string[];
  tableIds: string[];
}

export interface IPopupUtils {
  /**
   * @param graphic
   * @param map
   */
  getPopupTitle(graphic: Graphic, map: Map): Promise<string>;
}

export interface IConsentResponse {
  granted: boolean;
}

export interface IPNContext extends Controller {
  managedLayers: IManagedLayers;
  managedTables: string[];
  highlightHandles: any[];
  removeHandles: () => void;
}

/** Key is the layer name and the value is the type of layer */
export type IManagedLayers = { [key: string]: "buffer" | "sketch"; };

/** Key is the layers guid */
export type IReportingOptions = { [key: string]: IReportingOption; };

export interface IReportingOption {
  reporting: boolean;
  comment: boolean;
  like: boolean;
  likeField?: string;
  dislike: boolean;
  dislikeField?: string;
  visible: boolean;
}

export interface ISortingInfo {
  field: string;
  order: "asc" | "desc";
}

export interface ISolutionItemHover {
  itemId: string;
  entering: boolean;
}

export interface ISolutionItemSelected {
  itemId: string;
  selected: boolean;
}

export interface ISolutionTypeHover {
  itemType: string;
  entering: boolean;
}

export type ChipType = "new" | "deployed" | "updated" | "deployedOlderVersion";

export type SortType = "relevance" | "title" | "new" | "updated" | "suggested" | "created";

export type SortOrder = "asc" | "desc";

export type FilterType = "type" | "industry" | "domain" | "owner" | "solution";

export const EIndustry: {
    AEC: string;
    AIRPORTPORTRAIL: string;
    BUSINESS: string;
    CONSERVATION: string;
    DEFENSE: string;
    FACILITIES: string;
    HEALTHANDHUMANSERVICES: string;
    PIPELINE: string;
    PUBLICSAFETY: string;
    RENEWABLES: string;
    STATEANDLOCALGOVERNMENT: string;
    TELECOMMUNICATIONS: string;
    UTILITIES: string;
};

export const EDomain: {
    AIRPORT: string;
    AGRICULTURE: string;
    ASSESSMENTANDTAXATION: string;
    DISTRICTENERGY: string;
    ELECTIONS: string;
    ELECTRIC: string;
    EMERGENCYMANAGEMENT: string;
    ENVIRONMENTANDNATURALRESOURCES: string;
    FIRESERVICE: string;
    FISHANDWILDLIFE: string;
    GAS: string;
    HEALTHANDHUMANSERVICES: string;
    LAWENFORCEMENT: string;
    NATURALRESOURCES: string;
    PARKS: string;
    PLANNINGANDDEVELOPMENT: string;
    PROTECTEDAREAS: string;
    PUBLICWORKS: string;
    SEWER: string;
    STORMWATER: string;
    TELECOMMUNICATIONS: string;
    TRANSPORTATION: string;
    WATER: string;
};

export type EType = "New Release" | "Suggested";

export type EOwnerOption = "My solutions" | `My organization's solutions`;

export interface IFilterOption {
  type: FilterType;
  displayValue: string;
  domain?: string;
  value: string | EType | EOwnerOption;
  industry?: string;
}

export interface IFilterSetting {
  categories?: IFilterOption[];
  searchTerm?: string;
  displayValue?: string;
}

export interface ISearchOption {
  searchTerm: string;
}

export interface ISortOption {
  sortType: SortType;
  enabled?: boolean;
}

export interface ISolutionDeployedCard {
  deployedDate: string;
  description: string;
  heading: string;
  itemId: string;
  owner: string;
  thumbnail: string;
  updateAvailable: boolean;
}

export interface IDeployedSolutionCards {
  cards: ISolutionInfoCard[];
  relatedSolutions: Set<string>;
}

export const BASE_DEPLOYED_TERMS: "((typekeywords:Deployed,\"ArcGIS Solution\") OR (typekeywords:Deployed,AIAssistant) OR ((typekeywords:Deployed) AND (created:[1577862000000 TO 1622576880000])))";

export const BASE_SOLUTIONS_TERMS: "(typekeywords:Solution,Template)";

export interface ISearchOptionPartial {
  q: string;
  filter: string;
  sortField: string;
  sortOrder: string;
  nextStart?: any;
  categories: string[];
  delay: boolean;
  getSuggested?: boolean;
  num: number;
}

export interface ICacheBatch<T> {
  cards: T[];
  paging: IPagedResponse;
}

export type IKeyedStrings = { [key: string]: string; };

export interface IPreview {
  name: string;
  format: string;
  alt: string;
}

/** Summary of a solution item. */
export interface ISolutionInfoCard extends ISortableItem {
  id: string;
  title: string;
  snippet: string;
  description: string;
  url: string;
  itemUrl: string;
  thumbnailFilename: string;
  thumbnailUrl: string;
  tryitUrl: string;
  typeKeywords: string[];
  learnMoreUrl: string;
  createdMs: number;
  created: string;
  modified: string;
  numViews: number;
  tags: string[];
  categories: string[];
  licenseInfo: string;
  deployCommonId: string;
  deployVersion: string;
  canDelete: boolean;
  preview?: IPreview[];
  sourcePortalUrl: string;
  knownToBePublicSource: boolean;
  waitId: string;
  relatedSolutions: string[];
  owner?: string;
  chips?: ChipType[];
  supportReuse?: boolean;
}

export type TEnvironments = "dev" | "qa" | "prod";

export interface ICacheBatch<T> {
  cards: T[];
  paging: IPagedResponse;
}

export type ISortableItem = { [key: string]: any; } & {
  createdMs: number;
  numViews: number;
  title: string;
};

export interface IURLParamPair {
  k: string;
  v: string;
}

export interface IRequestDeploySolution {
  card: ISolutionInfoCard;
  reuse: boolean;
  jobId: string;
  userOptions: IUserOption[];
}

export interface IUserOption {
  id: string;
  props: IUserProp[];
  accordionDisplay?: boolean;
}

export interface IUserProp {
  autoSelect?: boolean;
  id?: string;
  itemType?: string;
  label?: string;
  prop?: string;
  default?: string;
  value?: string;
  responseValue?: string;
  choices?: string[];
  valueType?: string;
  attributes?: any;
  validation?: any;
  valid?: boolean;
  validId?: boolean;
  srSearchText?: string;
  outType?: string;
  loading?: boolean;
  tooltip?: string;
  name?: string;
  title?: string;
  itemUrl?: string;
  existingItemId?: string;
}

export interface IValidationResult {
  isValid: boolean;
  errorType: null | "empty" | "exceed-length" | "special-character" | "not-unique" | "invalid-format" | "sql-keyword" | "system-field" | "duplicate-field" | "out-of-range";
}

export type TrackingEnv = "dev" | "qa" | "prod" | "";

export interface IDeployProgressUpdate {
  id: string;
  progress: number;
}

export interface IDeployFailed {
  card: ISolutionInfoCard;
  jobId: string;
  error?: any;
}

export const PORTAL_ADD_MEMBERS_TO_GROUP: "portal:user:addExternalMembersToGroup";

export const PORTAL_CREATE_ITEM: "portal:user:createItem";

export const PORTAL_CREATE_GROUP: "portal:user:createGroup";

export const PORTAL_PUBLISH_BD_ANALYTICS: "portal:publisher:publishBigDataAnalytics";

export const PORTAL_PUBLISH_FEATURES: "portal:publisher:publishFeatures";

export const PORTAL_PUBLISH_FEEDS: "portal:publisher:publishFeeds";

export const PORTAL_PUBLISH_GP: "portal:publisher:publishServerGPServices";

export const PORTAL_PUBLISH_RT_ANALYTICS: "portal:publisher:publishRealTimeAnalytics";

export const PORTAL_SHARE_TO_GROUP: "portal:user:shareToGroup";

export const SOLUTIONS_HUB_PREMIUM: "solutions:hubPremium";

export const SOLUTIONS_NOTEBOOK: "solutions:notebook";

export const SOLUTIONS_TRACKING_ADMIN_TRACKING: "solutions:locationtracking:admin:tracking";

export const SOLUTIONS_TRACKING: "solutions:locationtracking:tracking";

export const SOLUTIONS_TRACKING_ADMIN: "solutions:locationtracking:admin";

export const SOLUTIONS_VELOCITY: "solutions:velocity";

export const SOLUTIONS_WORKFLOW_MANAGER: "solutions:workflowManager";

export interface IItemPreview {
  name: string;
  format: string;
  alt: string;
  description?: string;
}

export interface IInfoProduct {
  item: string;
  description: string;
  userType: string;
}

export interface IReleaseNote {
  version: string;
  description: string;
}

export interface IItemProperties {
  schemaVersion: number;
  learnMoreUrl: string;
  preview: IItemPreview[];
  relatedSolutions: string[];
  requirements: string[];
  infoProducts: IInfoProduct[];
  releaseNotes: IReleaseNote[];
  dataDictionaryURL: string;
  demoURL: string;
  relatedResources: any[];
}

export interface IPrivilegeMessages {
  leadingMessages: string[];
  bulletedMessages: string[];
  trailingMessages: string[];
}

export type IDeployedSolutionCardRefs = { [key: string]: SolutionDeployedCard; };

export const ITEM_TITLE_LENGTH: 250;

export const DEFAULT_TEXT_FIELD_LENGTH: 256;

export type DeployAppTab = "all-solutions" | "deployments" | "details" | "resources" | "deployed-card" | "my-content";

export interface IActiveTab {
  tabType: DeployAppTab;
  tabTitleOrId: string;
}

export type FieldSortType = "default" | "display" | "field" | "type";

export type NameType = "folder" | "item";

export const TELEMETRY_CATEGORY: {
    readonly SOLUTION_DETAILS: "Solution Details";
    readonly GLOBAL_NAVIGATION: "Global Nav";
    readonly ALL_SOLUTIONS: "Solutions";
    readonly DEPLOYMENTS: "Deployments";
    readonly ASSISTANT: "Assistant";
    readonly RESOURCES: "Resources";
    readonly BUILDER: "Solution Builder";
};

export type TelemetryCategory = typeof TELEMETRY_CATEGORY[keyof typeof TELEMETRY_CATEGORY];

export interface ITelemetryDimensions {
  dimension1?: string;
  dimension2?: string;
  dimension3?: string;
  dimension4?: string;
  dimension5?: string;
  dimension6?: string;
  dimension7?: string;
  dimension8?: string;
  dimension9?: string;
  dimension10?: string;
  dimension11?: string;
  dimension12?: string;
  dimension13?: string;
  dimension14?: string;
  dimension15?: string;
  dimension16?: string;
  dimension17?: string;
  dimension18?: string;
  dimension19?: string;
  dimension20?: string;
}

export interface ITelemetryMetrics {
  metric1?: number;
  metric2?: number;
  metric3?: number;
  metric4?: number;
  metric5?: number;
  metric6?: number;
  metric7?: number;
  metric8?: number;
  metric9?: number;
  metric10?: number;
  metric11?: number;
  metric12?: number;
  metric13?: number;
  metric14?: number;
  metric15?: number;
  metric16?: number;
  metric17?: number;
  metric18?: number;
  metric19?: number;
  metric20?: number;
}

export interface ITelemetrySession {
  instance?: Telemetry;
  logEvent: (options: {
      category: string;
      action: string;
      label?: string;
      details?: string;
      dimensions?: string[];
      metrics?: number[];
  }) => void;
  enabled: boolean;
}

export interface ITelemetryOptions {
  name: string;
  version: string;
  dev?: IAmazonTelemetryOptions;
  prod?: IAmazonTelemetryOptions;
  qa?: IAmazonTelemetryOptions;
}

export interface IAmazonTelemetryOptions {
  amazon: {
      userPoolID: string;
      app: { id: string; };
  };
}

export interface IAppConfig {
  agolPortalUrl: string;
  anonAgolSession?: UserSession;
  authentication?: Auth;
  allCards: ISolutionInfoCard[];
  diagramKey: string;
  languageDirection?: "ltr" | "rtl";
  languageResource?: string;
  orgUrl: string;
  page?: IAppPage;
  userSession?: UserSession;
  telemetrySession?: ITelemetrySession;
  v1SolutionId?: string;
  queryParams?: IQueryParams;
  agoBasedEnterpriseSolutionsGroupId: string;
  appId: string;
  isEnterprise: boolean;
  portalURL: string;
  primarySolutionsGroupId: string;
  locale: string;
  measurementIds?: string[];
  forceTrackingEnv?: TEnvironments | "";
}

export interface IAppPage {
  pageType: DeployAppTab;
  solutionTitleOrId?: string;
}

export interface IAppPageInit {
  page: IAppPage;
  v1SolutionId?: string;
  queryParams: IQueryParams;
}

export interface IQueryParams {
  domain: string | null;
  industry: string | null;
  locale: string;
  offerType: string | null;
  searchTerm: string | null;
  sortField: string | null;
  signInParam: string | null;
  filter: string | null;
}

export const EDeploymentsTypeFilter: {
    MINE: string;
    ORG: string;
};

export const EOfferType: {
    BOTH: string;
    NEW: string;
    SUGGESTED: string;
};

export const ESortField: {
    NEW: string;
    NUMVIEWS: string;
    RELEVANCE: string;
    SUGGESTED: string;
    TITLE: string;
    UPDATED: string;
    CREATED: string;
};

export const ESignInParam: {
    DEPLOY: string;
    AIOPEN: string;
};

export interface IQuickLink {
  icon: Icon["icon"];
  label: string;
  url: string;
}

export interface INavTab {
  tabType: DeployAppTab;
  card?: ISolutionInfoCard;
}

export interface IDeployCard {
  card: ISolutionInfoCard;
  cardRef?: SolutionDeployedCard;
}

export interface IDeployingCarouselMessage {
  message: string;
  url?: string;
  icon?: Icon["icon"];
}

export interface IOrgSettings {
  aiAssistantsEnabled?: boolean;
  blockBetaApps?: boolean;
  colocateCompute?: boolean;
  searchArcGISOnlineEnabled?: boolean;
}

export interface ResourceCard {
  icon?: string;
  meridianIcon?: string;
  heading: string;
  description: string;
  url?: string;
  headingEn?: string;
  sectionHeadingEn?: string;
}

export interface IDeployCardFetchFailed {
  title: string;
  message: string;
}

export interface IGlobalAlert {
  id: string;
  kind: "success" | "danger" | "warning" | "info";
  icon?: string;
  title?: string;
  message: string;
  autoClose?: boolean;
  autoCloseDuration?: "fast" | "medium" | "slow";
}

/**
 * Root interface for solution design JSON
 * Simplified design-time representation, separate from deployment template format
 */
export interface ISolutionDesign {
  solution: ISolutionDesignItemProps;
  items: ISolutionDesignContentItem[];
  featureLayer: ISolutionDesignFeatureLayer;
  sourceBuildSolution?: any;
  /**
   * Top-level template parameters carried through from the source template
   * item data. Present when the template advertises user-configurable
   * deployment options (e.g. `params.wkid` for spatial reference).
   */
  params?: Record<string, any> | null;
}

/**
 * Solution metadata for design phase
 * Simplified from \@esri/solution-common IItem - only fields needed for design/editing
 */
export interface ISolutionDesignItemProps {
  itemId?: string | null;
  title: string;
  snippet?: string;
  description?: string;
  tags?: string[];
  thumbnailUrl?: string;
  strings?: ISolutionDesignString[];
}

/** Template string key-value pair for solution templatization */
export interface ISolutionDesignString {
  key: string;
  value: string;
  description?: string;
}

/**
 * Simplified item representation for design phase
 * Uses human-readable type strings that will be parsed for display
 */
export interface ISolutionDesignContentItem {
  id: string;
  title: string;
  description: string;
  type: string;
}

/** Feature layer configuration section */
export interface ISolutionDesignFeatureLayer {
  readonly itemId?: string;
  addLayers: boolean;
  layers: ISolutionDesignLayerOrTable[];
}

/** Feature layer or table specification */
export interface ISolutionDesignLayerOrTable {
  name: string;
  description?: string;
  readonly id?: string;
  type: "Point" | "Polyline" | "Polygon" | "Table";
  typeMutable: boolean;
  readonly geometryType?: "esriGeometryPoint" | "esriGeometryPolyline" | "esriGeometryPolygon" | "esriGeometryNull";
  customFields: ISolutionDesignCustomField[];
  requiredFields: ISolutionDesignRequiredField[];
  systemFields: ISolutionDesignSystemField[];
}

/** Custom field (fully editable) */
export interface ISolutionDesignCustomField {
  name: string;
  type: "string" | "integer" | "double" | "date" | "guid";
  alias: string;
  description?: string;
  choiceList?: string[] | null;
  length?: number;
}

/** Required field configuration (limited editing - alias/description only) */
export interface ISolutionDesignRequiredField {
  readonly name: string;
  readonly type: "string" | "integer" | "double" | "date" | "guid";
  alias: string;
  description?: string;
  readonly choiceList?: string[] | null;
  readonly length?: number;
}

/** System field configuration (limited editing - alias/description only) */
export interface ISolutionDesignSystemField {
  readonly name: string;
  readonly type: "string" | "integer" | "double" | "date" | "guid" | "oid" | "globalid";
  alias: string;
  description?: string;
}

/** History entry for undo/redo functionality */
export interface ISolutionDesignHistoryEntry {
  design: ISolutionDesign;
  timestamp: number;
}

/** Builder editing state for mutual exclusion with chat */
export interface ISolutionDesignEditingState {
  isEditingInBuilder: boolean;
  isAgentProcessing: boolean;
}

/** Context interface for solution builder design state */
export interface ISolutionDesignBuilderContext {
  design: ISolutionDesign | null;
  updateDesign: (design: ISolutionDesign | null) => void;
  isBuilderVisible: boolean;
  setBuilderVisible: (visible: boolean) => void;
}

/** Minimal solution metadata used for embedding search and match confirmation. */
export interface SolutionItem {
  /** Stable solution identifier, derived from type keywords when available. */
  id: string;
  /** Display title shown to users in search and confirmation messaging. */
  title: string;
  /** Short summary pulled from portal item metadata. */
  snippet: string;
  /** Plain-text description used for embeddings and match validation. */
  description: string;
  /** Optional embedding vector loaded from persisted cache data. */
  embedding?: number[];
}

/** Search result pairing a candidate solution with its similarity score. */
export interface SolutionMatch {
  /** Candidate solution metadata. */
  solution: SolutionItem;
  /** Similarity score between the request and the candidate solution. */
  score: number;
}