/*
 * THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
 */

import { l } from '@atproto/lex'
import * as BookhiveDefs from './defs.defs.js'

const $nsid = 'buzz.bookhive.book'

export { $nsid }

/** A book in the user's library */
type Main = {
  $type: 'buzz.bookhive.book'

  /**
   * Cover image of the book
   */
  cover?: l.BlobRef

  /**
   * Whether the user owns this book
   */
  owned?: boolean

  /**
   * Number of stars given to the book (1-10) which will be mapped to 1-5 stars
   */
  stars?: number

  /**
   * The title of the book
   */
  title: string

  /**
   * The book's hive id, used to correlate user's books with the hive
   */
  hiveId: string

  /**
   * The book's review
   */
  review?: string
  status?:
    | 'buzz.bookhive.defs#finished'
    | 'buzz.bookhive.defs#reading'
    | 'buzz.bookhive.defs#wantToRead'
    | 'buzz.bookhive.defs#abandoned'
    | l.UnknownString

  /**
   * The authors of the book (tab separated)
   */
  authors: string
  createdAt: l.DatetimeString

  /**
   * The date the user started reading the book
   */
  startedAt?: l.DatetimeString

  /**
   * The date the user finished reading the book
   */
  finishedAt?: l.DatetimeString

  /**
   * AT-URI of the canonical catalogBook record in @bookhive.buzz
   */
  hiveBookUri?: string

  /**
   * External identifiers for the book
   */
  identifiers?: BookhiveDefs.BookIdentifiers

  /**
   * Progress tracking details for the book
   */
  bookProgress?: BookhiveDefs.BookProgress
}

export type { Main }

/** A book in the user's library */
const main = /*#__PURE__*/ l.record<'tid', Main>(
  'tid',
  $nsid,
  /*#__PURE__*/ l.object({
    cover: /*#__PURE__*/ l.optional(
      /*#__PURE__*/ l.blob({
        accept: ['image/png', 'image/jpeg'],
        maxSize: 1000000,
      }),
    ),
    owned: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),
    stars: /*#__PURE__*/ l.optional(
      /*#__PURE__*/ l.integer({ maximum: 10, minimum: 1 }),
    ),
    title: /*#__PURE__*/ l.string({ maxLength: 512, minLength: 1 }),
    hiveId: /*#__PURE__*/ l.string(),
    review: /*#__PURE__*/ l.optional(
      /*#__PURE__*/ l.string({ maxGraphemes: 15000 }),
    ),
    status: /*#__PURE__*/ l.optional(
      /*#__PURE__*/ l.string<{
        knownValues: [
          'buzz.bookhive.defs#finished',
          'buzz.bookhive.defs#reading',
          'buzz.bookhive.defs#wantToRead',
          'buzz.bookhive.defs#abandoned',
        ]
      }>(),
    ),
    authors: /*#__PURE__*/ l.string({ maxLength: 2048, minLength: 1 }),
    createdAt: /*#__PURE__*/ l.string({ format: 'datetime' }),
    startedAt: /*#__PURE__*/ l.optional(
      /*#__PURE__*/ l.string({ format: 'datetime' }),
    ),
    finishedAt: /*#__PURE__*/ l.optional(
      /*#__PURE__*/ l.string({ format: 'datetime' }),
    ),
    hiveBookUri: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
    identifiers: /*#__PURE__*/ l.optional(
      /*#__PURE__*/ l.ref<BookhiveDefs.BookIdentifiers>(
        (() => BookhiveDefs.bookIdentifiers) as any,
      ),
    ),
    bookProgress: /*#__PURE__*/ l.optional(
      /*#__PURE__*/ l.ref<BookhiveDefs.BookProgress>(
        (() => BookhiveDefs.bookProgress) as any,
      ),
    ),
  }),
)

export { main }

export const $type = $nsid
export const $isTypeOf = /*#__PURE__*/ main.isTypeOf.bind(main)
export const $build = /*#__PURE__*/ main.build.bind(main)
export const $assert = /*#__PURE__*/ main.assert.bind(main)
export const $check = /*#__PURE__*/ main.check.bind(main)
export const $cast = /*#__PURE__*/ main.cast.bind(main)
export const $ifMatches = /*#__PURE__*/ main.ifMatches.bind(main)
export const $matches = /*#__PURE__*/ main.matches.bind(main)
export const $parse = /*#__PURE__*/ main.parse.bind(main)
export const $safeParse = /*#__PURE__*/ main.safeParse.bind(main)
export const $validate = /*#__PURE__*/ main.validate.bind(main)
export const $safeValidate = /*#__PURE__*/ main.safeValidate.bind(main)
