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

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

   #: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
   #:write-iso-date

   #:today))

(uiop:define-package #:org.ajoberstar.quixote.model
  (:use #:common-lisp)
  (:local-nicknames (#:dates #:org.ajoberstar.quixote.dates))
  (:export
   #:entity
   #:entity-id
   #:entity-created-at
   #:entity-updated-at

   #:book
   #:book-id
   #:book-title
   #:book-author
   #:book-year
   #:book-type
   #:book-pages
   #:book-isbn
   #:book-cover
   #:make-book

   #:readthrough
   #:readthrough-id
   #:readthrough-book
   #:readthrough-started-at
   #:readthrough-completed-at
   #:make-readthrough

   #:reading
   #:reading-id
   #:reading-readthrough
   #:reading-at
   #:reading-page-start
   #:reading-page-end
   #:reading-pages
   #:make-reading))

(uiop:define-package #:org.ajoberstar.quixote.db
  (:use #:common-lisp)
  (:local-nicknames (#:dates #:org.ajoberstar.quixote.dates)
                    (#:model #:org.ajoberstar.quixote.model))
  (:export
   #:sql-connect
   #:sql-disconnect
   #:with-connection
   #:sql-migrate

   #:select-books
   #:select-book
   #:insert-book
   #:update-book
   #:delete-book

   #:select-book-cover
   #:update-book-cover
   #:delete-book-cover

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

   #:select-readings
   #:select-readthrough-readings
   #:select-reading
   #:insert-reading
   #:update-reading
   #:delete-reading))

(uiop:define-package #:org.ajoberstar.quixote.openlibrary
  (:use #:common-lisp)
  (:local-nicknames (#:jzon #:com.inuoe.jzon)
                    (#:model #:org.ajoberstar.quixote.model))
  (:export
   #:book-search
   #:cover))

(uiop:define-package #: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
   #:pace
   #:progress))

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

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