## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")

## -----------------------------------------------------------------------------
library(data.table)
library(zot)

## -----------------------------------------------------------------------------
ztCleanName("Dynamics (1).pdf")
ztCleanTitle("Dynamics (1).pdf")

Payload <- list(
  itemType = "book",
  title = "Structural Analysis (1).pdf",
  creators = list(list(
    creatorType = "author",
    firstName = "A.",
    lastName = "Author"
  )),
  filename = "Structural Analysis (1).pdf"
)
ztCleanPayload(Payload)

## -----------------------------------------------------------------------------
Items <- data.table(
  itemKey = c("A", "B"),
  library = "user",
  title = c("Reviewed book (1).pdf", "Existing title")
)

RetitlePlan <- ztRetitle(Items, transform = ztCleanTitle)
zotPreview(RetitlePlan, describe = "Normalize reviewed titles")

## -----------------------------------------------------------------------------
zotSameItem(
  list(doi = "10.1000/Example", hasFile = TRUE),
  list(doi = "10.1000/example", hasFile = TRUE)
)

zotSameItem(
  list(title = "Introduction"),
  list(title = "Introduction")
)

## -----------------------------------------------------------------------------
Records <- data.table(
  itemKey = c("A", "B", "C"),
  title = c("Paper", "Paper", "Paper"),
  year = c(2026L, 2026L, NA_integer_),
  author = c("Lovelace", "Lovelace", NA_character_),
  doi = NA_character_,
  md5 = NA_character_,
  hasFile = FALSE
)
ztTwins(Records)

## -----------------------------------------------------------------------------
Message <- function(doi) list(
  title = list("A reproducible record"),
  author = list(list(given = "Ada", family = "Lovelace")),
  `container-title` = list("Example Journal"),
  issued = list(`date-parts` = list(list(2026L)))
)

ztCrossref("10.1000/example", getJson = Message)

## -----------------------------------------------------------------------------
MoveRecords <- data.table(
  itemKey = "OLD1",
  payload = list(list(itemType = "book", title = "Reviewed book")),
  hasFile = FALSE
)

CreatePlan <- ztBlockMoveCreate(
  MoveRecords,
  toLibrary = "5107760",
  collectionKey = "DEST"
)
CreatePlan

## -----------------------------------------------------------------------------
CreateLedger <- list(items = list(
  `create-1` = list(status = "done", new = "NEW1")
))

TrashPlan <- ztBlockMoveTrash(
  MoveRecords,
  createLedger = CreateLedger,
  fromLibrary = "user"
)
TrashPlan

