import type { DateISOString } from "@/types/date-serialization"

import type { EmptyResponse, SuccessResponse } from "../../types"

// Request types
export interface CreateRSSHubInstanceRequest {
  id?: string
  baseUrl: string
  accessKey?: string
}

export interface DeleteRSSHubInstanceRequest {
  id: string
}

export interface UseRSSHubInstanceRequest {
  id: string | null
  durationInMonths?: number
  twoFactorCode?: string
  backupCode?: string
}

export interface GetRSSHubInstanceRequest {
  id: string
}

// Response data types
export interface RSSHubInstanceOwner {
  id: string
  handle: string | null
  name: string | null
  image: string | null
}

export interface RSSHubInstanceListItem {
  id: string
  ownerUserId: string
  price: number
  userLimit: number | null
  description: string | null
  errorMessage: string | null
  errorAt: DateISOString | null
  userCount: number
  owner: RSSHubInstanceOwner | null
}

export interface RSSHubInstanceDetails {
  id: string
  ownerUserId: string
  price: number
  userLimit: number | null
  description: string | null
  errorAt: DateISOString | null
  errorMessage: string | null
  baseUrl?: string | null
  accessKey?: string | null
}

export interface RSSHubPurchase {
  hash: string | null
  expiresAt: string
}

export interface RSSHubInstanceData {
  instance: RSSHubInstanceDetails
  purchase: RSSHubPurchase | null
}

export interface RSSHubUsage {
  id: string
  rsshubId: string
  userId: string
}

export interface RSSHubStatusData {
  usage?: RSSHubUsage
  purchase: RSSHubPurchase | null
}

// Response types
export type CreateRSSHubInstanceResponse = EmptyResponse
export type GetRSSHubInstancesListResponse = SuccessResponse<
  RSSHubInstanceListItem[]
>
export type DeleteRSSHubInstanceResponse = EmptyResponse
export type UseRSSHubInstanceResponse = EmptyResponse
export type GetRSSHubInstanceResponse = SuccessResponse<RSSHubInstanceData>
export type GetRSSHubStatusResponse = SuccessResponse<RSSHubStatusData>
