;; SPDX-FileCopyrightText: 2026 Andrew Oberstar <andrew@ajoberstar.org>
;; SPDX-License-Identifier: AGPL-3.0-only

(in-package #:common-lisp-user)

(defpackage #:org.ajoberstar.quixote.dates
  (:use #:common-lisp)
  (:export
   #:date
   #:make-date
   #:make-date-ordinal
   #:date-ordinal
   #:date-year
   #:date-month
   #:date-day
   #:date-dow
   #:date-month-name
   #:date-day-name

   #:minimum-date
   #:maximum-date
   #:minimum-ordinal
   #:maximum-ordinal

   #:date-leap-year-p
   #:date-day-of-year

   #:date-diff
   #:date-
   #:date<
   #:date<=
   #:date=
   #:date>
   #:date>=
   #:date-1+
   #:date+
   #:date-
   #:date-next
   #:date-prev
   #:date-start-of-year
   #:date-start-of-quarter
   #:date-start-of-month

   #:parse-iso-date
   #:parse-us-date
   #:parse-dmy-date
   #:parse-mdy-date
   #:parse-lax-date
   #:write-iso-date
   #:write-us-date
   #:write-human-date

   #:today))

(defpackage #:org.ajoberstar.quixote.model
  (:use #:common-lisp)
  (:local-nicknames (#:dates #:org.ajoberstar.quixote.dates))
  (:export
   #:+domain-types+
   #:+statuses+

   #:entity
   #:entity-id
   #:entity-created-at
   #:entity-updated-at

   #:author
   #:author-id
   #:author-name
   #:author-sort-name
   #:author-birth
   #:author-death
   #:author-bookbrainz-id
   #:author-openlibrary-id
   #:author-wikidata-id
   #:make-author

   #:edition
   #:edition-id
   #:edition-title
   #:edition-full-title
   #:edition-sort-title
   #:edition-disambiguation
   #:edition-author
   #:edition-translator
   #:edition-page-start
   #:edition-page-end
   #:edition-pages
   #:edition-type
   #:edition-year
   #:edition-isbn
   #:edition-bookbrainz-id
   #:edition-openlibrary-id
   #:edition-wikidata-id
   #:make-edition

   #:part
   #:part-id
   #:part-edition
   #:part-title
   #:part-sort-title
   #:part-title-p
   #:part-segment
   #:part-page-start
   #:part-page-end
   #:part-pages
   #:part-page-start-str
   #:part-page-end-str
   #:part-page-range
   #:part-partial-p
   #:part-bookbrainz-id
   #:part-openlibrary-id
   #:part-wikidata-id
   #:make-part

   #:collection
   #:collection-id
   #:collection-title
   #:collection-type
   #:collection-type-friendly
   #:make-collection

   #:item
   #:item-id
   #:item-collection
   #:item-position
   #:item-item
   #:make-item

   #:tree
   #:tree-collection
   #:tree-item
   #:tree-children
   #:tree-find
   #:tree-map-collections
   #:tree-map-parts
   #:make-tree

   #:readthrough
   #:readthrough-id
   #:readthrough-collection
   #:readthrough-status
   #:readthrough-status-friendly
   #:readthrough-active-p
   #:readthrough-started-at
   #:readthrough-ended-at
   #:make-readthrough

   #:reading
   #:reading-id
   #:reading-readthrough
   #:reading-part
   #:reading-status
   #:reading-status-friendly
   #:reading-active-p
   #:reading-started-at
   #:reading-ended-at
   #:make-reading

   #:session
   #:session-id
   #:session-reading
   #:session-at
   #:session-page-start
   #:session-page-end
   #:session-pages
   #:session-page-start-str
   #:session-page-end-str
   #:session-page-range
   #:make-session))

(defpackage #:org.ajoberstar.quixote.covers
  (:use #:common-lisp)
  (:local-nicknames (#:model #:org.ajoberstar.quixote.model))
  (:export
   #:*covers-dir*
   #:sides
   #:cover
   #:make-cover
   #:cover-dir
   #:cover-path
   #:probe-cover-path
   #:ensure-cover-empty
   #:delete-cover
   #:cover-exists-p))

(defpackage #:org.ajoberstar.quixote.db
  (:use #:common-lisp)
  (:shadow #:search)
  (:local-nicknames (#:covers #:org.ajoberstar.quixote.covers)
                    (#:dates #:org.ajoberstar.quixote.dates)
                    (#:jzon #:com.inuoe.jzon)
                    (#:model #:org.ajoberstar.quixote.model))
  (:export
   #:sql-connect
   #:sql-disconnect
   #:with-connection
   #:with-transaction
   #:sql-migrate

   #:select-authors
   #:select-author
   #:search-authors
   #:insert-author
   #:update-author
   #:delete-author

   #:select-editions
   #:select-author-editions
   #:select-recent-editions
   #:select-edition
   #:search-editions
   #:insert-edition
   #:update-edition
   #:delete-edition

   #:select-edition-cover
   #:update-edition-cover
   #:delete-edition-cover

   #:select-parts
   #:select-orphan-parts
   #:select-edition-parts
   #:search-parts
   #:select-part
   #:insert-part
   #:update-part
   #:delete-part

   #:select-collection-items
   #:select-collection-item
   #:insert-collection-item
   #:update-collection-item
   #:delete-collection-item
   #:select-content-items
   #:select-collections
   #:select-root-collections
   #:select-collection
   #:search-collections
   #:insert-collection
   #:update-collection
   #:delete-collection
   #:select-collection-tree
   #:select-collection-breadcrumbs

   #:select-readthroughs
   #:select-active-readthroughs
   #:select-collection-readthroughs
   #:select-readthrough
   #:insert-readthrough
   #:update-readthrough
   #:delete-readthrough

   #:select-readings
   #:select-readthrough-readings
   #:select-edition-readings
   #:select-part-readings
   #:select-part-orphan-readings
   #:select-active-readings
   #:select-active-parts-readings
   #:select-reading
   #:insert-reading
   #:update-reading
   #:delete-reading

   #:select-sessions
   #:select-collection-tree-sessions
   #:select-readthrough-sessions
   #:select-reading-sessions
   #:select-session
   #:insert-session
   #:update-session
   #:delete-session))

(defpackage #:org.ajoberstar.quixote.search
  (:use #:common-lisp)
  (:shadow #:search)
  (:local-nicknames (#:db #:org.ajoberstar.quixote.db)
                    (#:model #:org.ajoberstar.quixote.model))
  (:export
   #:search))

(defpackage #:org.ajoberstar.quixote.openlibrary
  (:use #:common-lisp)
  (:local-nicknames (#:jzon #:com.inuoe.jzon)
                    (#:dates #:org.ajoberstar.quixote.dates)
                    (#:model #:org.ajoberstar.quixote.model))
  (:export
   #:author
   #:book
   #:work
   #:book-search))

(defpackage #:org.ajoberstar.quixote.stats
  (:use #:common-lisp)
  (:local-nicknames (#:dates #:org.ajoberstar.quixote.dates)
                    (#:db #:org.ajoberstar.quixote.db)
                    (#:model #:org.ajoberstar.quixote.model))
  (:export
   #:year-pages
   #:quarter-pages
   #:week-pages
   #:daily-pages
   #:pace
   #:progress
   #:rolling
   #:week-activity))

(defpackage #:org.ajoberstar.quixote.import
  (:use #:common-lisp)
  (:local-nicknames (#:covers #:org.ajoberstar.quixote.covers)
                    (#:dates #:org.ajoberstar.quixote.dates)
                    (#:db #:org.ajoberstar.quixote.db)
                    (#:lib #:org.ajoberstar.quixote.openlibrary)
                    (#:model #:org.ajoberstar.quixote.model)
                    (#:search #:org.ajoberstar.quixote.search))
  (:import-from #:spinneret
                #:with-html
                #:with-html-string
                #:*html-style*
                #:*always-quote*)
  (:export
   #:*default-edition-type*

   #:start
   #:stop

   #:image
   #:image-path
   #:image-thumb-path
   #:image-rethumb
   #:image-delete

   #:crop-args
   #:crop-args-left
   #:crop-args-right
   #:crop-args-top
   #:crop-args-bottom
   #:crop-args-rotate
   #:make-crop-args

   #:side
   #:side-original
   #:side-cropped
   #:side-crop-args
   #:make-side
   #:side-image
   #:side-recrop
   #:side-uncrop

   #:staged-item
   #:staged-item-id
   #:staged-item-name
   #:staged-item-dir
   #:staged-item-cover
   #:staged-item-cover-exists-p
   #:staged-item-front
   #:staged-item-back
   #:staged-item-isbn
   #:staged-item-edition
   #:staged-item-status
   #:staged-item-paired-p
   #:staged-item-identified-p

   #:staged-items
   #:staged-authors
   #:resolve-staged-authors
   #:author-match
   #:author-matches
   #:edition-match
   #:edition-matches

   #:staged-item-side
   #:lookup-staged-item
   #:queue-complete-item
   #:complete-staged-item
   #:delete-staged-item))

(defpackage #:org.ajoberstar.quixote.server
  (:use #:common-lisp)
  (:local-nicknames (#:covers #:org.ajoberstar.quixote.covers)
                    (#:dates #:org.ajoberstar.quixote.dates)
                    (#:db #:org.ajoberstar.quixote.db)
                    (#:import #:org.ajoberstar.quixote.import)
                    (#:jzon #:com.inuoe.jzon)
                    (#:lib #:org.ajoberstar.quixote.openlibrary)
                    (#:model #:org.ajoberstar.quixote.model)
                    (#:search #:org.ajoberstar.quixote.search)
                    (#:stats #:org.ajoberstar.quixote.stats))
  (:import-from #:spinneret
                #:with-html
                #:with-html-string
                #:*html-style*
                #:*always-quote*)
  (:export
   #:*static-dir*
   #:start
   #:stop))

(defpackage #:org.ajoberstar.quixote
  (:use #:common-lisp)
  (:local-nicknames (#:db #:org.ajoberstar.quixote.db)
                    (#:server #:org.ajoberstar.quixote.server))
  (:export
   #:main))
