import type { StructuredSuccessResponse } from "../../types"

export interface UpdateAsset {
  id: number
  name: string
  size: number
  downloadUrl: string
  contentType?: string | null
  sha512?: string | null
}

export interface UpdateRelease {
  id: number
  name: string | null
  tagName: string
  version: string
  publishedAt: string | null
  body?: string | null
  url: string
  assets: UpdateAsset[]
}

export interface RendererUpdate {
  version: string
  hash: string
  mainHash: string
  filename: string
  downloadUrl: string | null
  size: number | null
  contentType?: string | null
  commit?: string | null
  manifest: {
    name: string
    downloadUrl: string
  }
}

export interface PlatformUpdateFile {
  filename: string
  sha512: string
  size: number
  downloadUrl: string | null
  contentType?: string | null
}

export interface PlatformUpdate {
  platform: string
  version: string
  releaseDate: string | null
  manifest: {
    name: string
    path: string
    downloadUrl: string
  }
  files: PlatformUpdateFile[]
}

export interface AppUpdate {
  version: string
  selectedPlatform: PlatformUpdate | null
  platforms: PlatformUpdate[]
}

export interface UpdateDecision {
  type: "renderer" | "app" | "none"
  renderer: RendererUpdate | null
  app: AppUpdate | null
}

export interface LatestReleasePayload {
  provider: string
  fetchedAt: string
  release: UpdateRelease
  decision: UpdateDecision
}

export type GetLatestReleaseResponse = StructuredSuccessResponse<LatestReleasePayload>

export interface GetLatestReleaseQuery {
  refresh?: string | boolean
}

export interface GetManifestRequest {
  manifestName: string
  refresh?: string | boolean
}

export type StoreDistribution = "mas" | "mss"

export interface DistributionStatusPayload {
  distribution: StoreDistribution
  storeUrl: string | null
  storeVersion: string | null
  rendererUpdate: RendererUpdate | null
}

export type GetDistributionStatusResponse = StructuredSuccessResponse<DistributionStatusPayload>

export interface GetDistributionStatusRequest {
  distribution: StoreDistribution
  refresh?: string | boolean
}
