import type { ISimpleLocalConfig, ISimpleLocalIntegrationProfile, ISimpleLocalSnapshot } from '../../core/index.js';

export const mealieDomain = "mealie";
export const mealieDefaultName = "Mealie";

export type TMealieSnapshotSource = 'http' | 'client' | 'provider' | 'manual' | 'snapshot' | 'runtime';

export interface IMealieRawData extends Record<string, unknown> {
  about?: Record<string, unknown>;
  user?: Record<string, unknown>;
  statistics?: Record<string, unknown>;
  mealplans?: Record<string, unknown>;
  shoppingLists?: Record<string, unknown>;
  shoppingItems?: Record<string, Record<string, unknown>>;
  fetchedAt?: string;
  errors?: Record<string, string>;
}

export type TMealieRawData = IMealieRawData;
export interface IMealieSnapshot extends ISimpleLocalSnapshot {}
export interface IMealieConfig extends ISimpleLocalConfig {
  url?: string;
  apiToken?: string;
  verifySsl?: boolean;
  macAddress?: string;
  deviceId?: string;
}

export const mealieProfile: ISimpleLocalIntegrationProfile = {
  domain: mealieDomain,
  displayName: "Mealie",
  manufacturer: "Mealie",
  model: "Mealie local integration",
  defaultName: mealieDefaultName,
  defaultProtocol: 'http',
  status: "control-runtime",
  platforms: [
    "sensor",
  ],
  serviceDomains: [],
  controlServices: [
    "get_mealplan",
    "get_recipe",
    "get_recipes",
    "get_shopping_list_items",
    "import_recipe",
    "set_mealplan",
    "set_random_mealplan",
  ],
  discoverySources: [
    'manual',
    'custom',
  ],
  discoveryKeywords: [
    "mealie",
    "Mealie",
  ],
  metadata: {
    "source": "home-assistant/core",
    "upstreamPath": "homeassistant/components/mealie",
    "upstreamDomain": "mealie",
    "integrationType": "service",
    "iotClass": "local_polling",
    "qualityScale": "platinum",
    "requirements": [
      "aiomealie==1.2.4",
    ],
    "codeowners": [
      "@joostlek",
      "@andrew-codechimp",
    ],
    "configFlow": true,
    "documentation": "https://www.home-assistant.io/integrations/mealie",
    "runtime": {
      "type": "control-runtime",
      "services": [
        "snapshot",
        "status",
        "refresh",
        "get_mealplan",
        "get_recipe",
        "get_recipes",
        "get_shopping_list_items",
        "import_recipe",
        "set_mealplan",
        "set_random_mealplan",
      ],
      "platforms": [
        "sensor",
      ],
      "controls": "delegated only to an injected client.execute or commandExecutor",
    },
    "localApi": {
      "implemented": [
        "local Mealie HTTP API snapshots using Bearer token auth against /api/app/about, /api/users/self, /api/households/statistics, mealplan, and shopping-list endpoints",
        "local Mealie HTTP services for get_mealplan, get_recipe, get_recipes, get_shopping_list_items, import_recipe, set_mealplan, and set_random_mealplan",
        "runtime mapping for Mealie statistics sensors plus mealplan and shopping-list counts",
        "safe snapshot/rawData/snapshotProvider/injected-client operation when no live endpoint is configured",
      ],
      "explicitUnsupported": [
        "Mealie ingress URLs containing /app/ because Home Assistant rejects ingress_url hosts and they are not a standalone local API base",
        "claiming live Mealie API success without config.host/config.url and config.token/apiToken, an injected native client, or snapshotProvider",
        "Home Assistant entity registry migrations and repair flows",
        "calendar/todo platform entity parity beyond the exposed service responses because the shared entity model currently has no calendar or todo platform type",
      ],
    },
  },
};
