export type OttCoreModuleStatus =
  | "contract_ready"
  | "blocked"
  | "not_connected"
  | "waiting_for_integration";

export type OttCoreModule = {
  id: string;
  name: string;
  responsibility: string;
  serves: string[];
  appContract: string;
  backendDependency: string;
  status: OttCoreModuleStatus;
  evidence: string;
};

export const ottCoreServedAppIds = [
  "web-pwa",
  "android-mobile",
  "ios-mobile",
  "android-tablet",
  "ipados",
  "chromeos-tablet",
  "fire-tablet",
  "windows-tablet",
  "android-tv",
  "fire-tv",
  "gaiaos",
  "roku",
  "tvos",
  "samsung-tizen",
  "lg-webos",
  "vizio",
  "vidaa"
];

export const ottCoreModules: OttCoreModule[] = [
  {
    id: "identity_profiles",
    name: "Identity / Profiles",
    responsibility: "Single account, device sessions, user profiles, kids profile gates and cross-device profile sync.",
    serves: ottCoreServedAppIds,
    appContract: "Every app receives the same signed-in user, active profile, profile restrictions and session state through a platform-specific shell.",
    backendDependency: "Identity service, session service, profile service",
    status: "blocked",
    evidence: "Auth/profile API integration and device session QA"
  },
  {
    id: "entitlements_subscriptions",
    name: "Entitlements / Subscriptions",
    responsibility: "Plan access, subscription status, purchase/rental rights, region restrictions, restore flows and playback authorization.",
    serves: ottCoreServedAppIds,
    appContract: "Every app must ask the core before playback or gated actions. Store-specific purchase UX is handled by the platform shell.",
    backendDependency: "Entitlement service, billing/store service, region policy service",
    status: "blocked",
    evidence: "Entitlement API, test plans, store credentials"
  },
  {
    id: "catalog_discovery",
    name: "Catalog / Discovery",
    responsibility: "Home rails, categories, title metadata, editorial collections, Live/Channels, recommendations and artwork hierarchy.",
    serves: ottCoreServedAppIds,
    appContract: "Same information architecture across apps; density and navigation change by platform.",
    backendDependency: "Catalog API, recommendation API, image/artwork service",
    status: "blocked",
    evidence: "Catalog API contract and platform layout QA"
  },
  {
    id: "search_deeplinks",
    name: "Search / Deep Links",
    responsibility: "Search suggestions, filters where suitable, recent searches, title links, collection links, campaigns and playback entry links.",
    serves: ottCoreServedAppIds,
    appContract: "Web/mobile may expose advanced search; TV minimizes typing and supports guided/voice/code-friendly discovery where available.",
    backendDependency: "Search API, deep-link router",
    status: "blocked",
    evidence: "Search/deep-link map and app routing QA"
  },
  {
    id: "playback_engine",
    name: "Playback Engine",
    responsibility: "ABR playback, DRM-ready architecture, subtitles, audio tracks, resume, next episode, skip intro/recap, error recovery and player telemetry.",
    serves: ottCoreServedAppIds,
    appContract: "Playback semantics stay consistent; control placement and input behavior change per platform.",
    backendDependency: "Manifest service, DRM/license service, player config service",
    status: "blocked",
    evidence: "Player QA matrix and stream/license tests"
  },
  {
    id: "watch_state",
    name: "Watch State / Personalization",
    responsibility: "Continue Watching, resume points, watch history, My List, recommendations feedback, profile personalization and device handoff.",
    serves: ottCoreServedAppIds,
    appContract: "Users can move between devices without losing context.",
    backendDependency: "Watch state API, personalization API",
    status: "blocked",
    evidence: "Cross-device resume and watchlist QA"
  },
  {
    id: "accessibility_localization",
    name: "Accessibility / Localization",
    responsibility: "Captions, subtitles, audio language, localized metadata/art, readable type, keyboard/focus/remote accessibility and RTL readiness where required.",
    serves: ottCoreServedAppIds,
    appContract: "Core exposes text/audio/caption options; platform shell applies native accessibility and input model.",
    backendDependency: "Subtitle/audio metadata service, localization assets",
    status: "blocked",
    evidence: "Accessibility and localization QA"
  },
  {
    id: "telemetry_health",
    name: "Analytics / Health",
    responsibility: "Browse, search, playback, buffering, completion, subscription funnel, ad events, errors, crashes and real platform health telemetry.",
    serves: ottCoreServedAppIds,
    appContract: "Only real connected telemetry is shown as ready. Missing SDK/API remains not_connected.",
    backendDependency: "Telemetry SDK/API, crash reporting, platform vitals",
    status: "not_connected",
    evidence: "Telemetry credentials and event validation"
  },
  {
    id: "brand_tokens",
    name: "Brand / Design Tokens",
    responsibility: "Shared color logic, typography rules, artwork ratios, icon language, spacing, motion principles and metadata hierarchy.",
    serves: ottCoreServedAppIds,
    appContract: "Same brand language, different shell: each platform adapts density, navigation, focus, gestures and controls.",
    backendDependency: "Design token package and asset pipeline",
    status: "contract_ready",
    evidence: "Design-system token contract"
  }
];

export function getOttCore() {
  return {
    schema: "trendest_shared_ott_core_v1",
    name: "Trendest Shared OTT Core",
    notASeparateApp: true,
    servesAppCount: ottCoreServedAppIds.length,
    serves: ottCoreServedAppIds,
    principle: "One shared OTT service/product core; 17 platform-native app clients.",
    modules: ottCoreModules
  };
}

export function getOttCoreModule(moduleId: string) {
  return ottCoreModules.find((module) => module.id === moduleId) || null;
}
