import type { TojuPluginInstallScope, TojuPluginManifest } from '../../../../shared-kernel';

export type PluginStoreInstallState = 'installed' | 'notInstalled' | 'updateAvailable';
export type PluginStoreActionLabel = 'Install' | 'Install to Server' | 'Remove from Server' | 'Uninstall' | 'Update' | 'Update Server';

export interface PluginStoreEntry {
  author?: string;
  bundleUrl?: string;
  description: string;
  githubUrl?: string;
  homepageUrl?: string;
  id: string;
  imageUrl?: string;
  installUrl?: string;
  readmeUrl?: string;
  scope?: TojuPluginInstallScope;
  sourceTitle?: string;
  sourceUrl: string;
  title: string;
  version: string;
}

export interface PluginStoreSourceResult {
  error?: string;
  loadedAt?: number;
  plugins: PluginStoreEntry[];
  title?: string;
  url: string;
}

export interface InstalledStorePlugin {
  bundleUrl?: string;
  cachedAt?: number;
  cachedSourcePath?: string;
  installedAt: number;
  installUrl?: string;
  manifest: TojuPluginManifest;
  sourceUrl?: string;
  updatedAt: number;
}

export interface PluginStoreReadme {
  pluginId: string;
  title: string;
  url: string;
  markdown: string;
}

export interface PersistedPluginStoreState {
  installedPlugins: InstalledStorePlugin[];
  sourceUrls: string[];
}

export interface PersistedServerPluginInstallState {
  schemaVersion?: number;
  servers?: Record<string, InstalledStorePlugin[]>;
}
