import BookItem from "./BookItem"
import { BookRibbonBadges } from "./BookRibbonBadge"
import { BookThumbnail } from "./components/BookThumbnail"
import { BookTag } from "./components/BookTag"
import { BookCategories, BookCategory } from "./components/BookCategories"
import { BookTitle } from "./components/BookTitle"
import ActionPanel from "./ActionPanel"
import RatingStarIndicatorWithTranslate, {
  RatingStarIndicator
} from "./RatingStarIndicator"
import BookItemWithDescription from "./BookItemWithDescription"
import EpisodeStatusTag from "./components/EpisodeStatusTag"

export type EpisodeItemStatusEnum = "DRAFT" | "DIRTY" | "PUBLISH"

export interface BookItemRatingSummary {
  average: number
  count: number
  eachCount: RatingInfoData[]
}
declare global {
  export interface PriceItemData {
    base: {
      silver: number
      gold: number
    }
  }

  export type RatingInfoData = {
    rating: number
    count: number

    // percent of indicator inside bar
    indicatorLevel?: number
  }
  export interface RecentReadItemData {
    offsetKey: string
    updatedAt: string
    bookId: any
    episodeId: any
  }
  export interface EpisodeItemData {
    publishedAt: string

    _id?: any
    title?: string
    viewCount?: number
    commentCount?: number
    isLockedBy?: boolean
    isOwner?: boolean
    isPurchased?: boolean
    isPublished?: boolean

    book?: BookItemData

    // TYPE ENUM reflect to
    // Book contentRating schema
    contentRating?: "GTE18" | "NORMAL"

    price?: PriceItemData
    // this reflect to enum file in schema
    // see: `graphql/episode/schema.ts`
    status?: EpisodeItemStatusEnum

    [key: string]: any
  }
  export interface BookItemData {
    publishedAt?: string
    isComplete?: boolean

    isInWishList?: boolean

    totalIncome?: {
      silver: number
      gold: number
    }

    isLockedBy?: "login" | "purchase"
    isOwner?: boolean
    isPurchased?: boolean
    isPublished?: boolean

    contentRating?: string
    thumbnailImage?: string
    recentRead?: RecentReadItemData
    synopsis?: string
    viewCount?: number
    author?: {
      _id: any
      name: string
      profilePicture: string
    }

    episodes?: EpisodeItemData[]
    // below 2 attributes
    // use same query as episodes
    // and saperated by prefix
    // (see ActionPanel fragments)
    firstEpisode?: Array<{ _id: string; title: string }>
    lastEpisode?: Array<{ publishedAt: string }>

    episodeCount?: number
    ratingSummary?: BookItemRatingSummary

    _id: any
    title?: string
    categories: string[]

    introduction?: any

    [key: string]: any
  }
}

export {
  BookItem,
  BookTag,
  RatingStarIndicatorWithTranslate,
  RatingStarIndicator,
  BookItemWithDescription,
  BookItemData,
  BookRibbonBadges,
  BookThumbnail,
  ActionPanel,
  BookTitle,
  BookCategories,
  BookCategory,
  EpisodeStatusTag
}
