#|

src/models/packages.lisp

Models Main Package List

|#

(in-package #:cl-user)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.generics
  (:use #:cl)
  (:export #:deck-id-of
           #:name-of
           #:ygo-archetype-of
           #:ygo-atk-of
           #:ygo-attribute-of
           #:ygo-def-of
           #:ygo-description-of
           #:ygo-frame-type-of
           #:ygo-level-of
           #:ygo-linkmarkers-of
           #:ygo-linkval-of
           #:ygo-passcode-of
           #:ygo-price-of
           #:ygo-race-of
           #:ygo-scale-of
           #:ygo-type-of))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.registered-table
  (:use #:cl
        #:cl-deck-builder2.db
        #:cl-deck-builder2.models.generics)
  (:import-from #:cl-deck-builder2.toolkit
                #:relative-pathname)
  (:export #:registry
           #:registered-classes
           #:registered-table-class
           #:ensure-tables-exist
           #:migration-expressions
           #:migrate-table
           #:export-registered-classes
           #:export-registered-classe-to-file))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.attachment
  (:use #:cl
        #:cl-deck-builder2.models.generics)
  (:import-from #:cl-deck-builder2.models.registered-table
                #:registered-table-class)
  (:import-from #:cl-deck-builder2.db
                #:create-dao)
  (:export #:attachment
           #:create-attachment
           #:attachment-valid-p))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.category
  (:use #:cl
        #:cl-deck-builder2.models.generics)
  (:import-from #:cl-deck-builder2.db
                #:create-dao
                #:select-dao)
  (:import-from #:cl-deck-builder2.models.registered-table
                #:registered-table-class)
  (:export #:category
           #:category-name-of
           #:category-left-of
           #:category-right-of

           #:category-rename

           #:category-insert-right-of
           #:category-insert-new-child
           #:category-insert-fake-data
           #:category-full-tree
           #:category-leaf-nodes
           #:category-full-tree-format
           #:category-delete-tree
           #:category-delete-and-reparent
           #:category-tree-depth
           #:category-node-depth
           #:category-subtree-depth
           #:category-subtree-max-depth

           #:by-category))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.ygoprodeck.fields
  (:use #:cl
        #:cl-deck-builder2.db
        #:cl-deck-builder2.models.generics)
  (:import-from #:cl-deck-builder2.models.registered-table
                #:registered-table-class)
  (:export #:variant
           #:name-of
           #:define-variant-list
           #:variant-condition
           #:variant-language
           #:ygo-banlist-name
           #:ygo-format-name
           #:ygo-linkmarker-name
           #:ygo-set-rarity-code))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.ygoprodeck
  (:use #:cl
        #:cl-deck-builder2.db
        #:cl-deck-builder2.models.generics
        #:cl-deck-builder2.models.registered-table)
  (:export :ygo-info
           #:ygo-description-of
           #:ygo-frame-type-of
           #:ygo-type-of
           #:ygo-passcode-of
           #:name-of
           #:ygo-race-of
           #:ygo-archetype-of
           #:ygo-attribute-of
           #:ygo-linkmarkers-of
           #:ygo-atk-of
           #:ygo-def-of
           #:ygo-level-of
           #:ygo-linkval-of
           #:ygo-scale-of))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.ygoprodeck.classes
  (:use #:cl
        #:cl-deck-builder2.models.generics
        #:cl-deck-builder2.models.ygoprodeck.fields)
  (:import-from #:cl-deck-builder2.models.registered-table
                #:registered-table-class)
  (:import-from #:cl-deck-builder2.models.ygoprodeck.fields
                #:variant-condition
                #:ygo-banlist-name
                #:ygo-format-name
                #:ygo-linkmarker-name
                #:ygo-set-rarity-code)
  (:import-from :cl-deck-builder2.toolkit
                :currency-deflate
                :currency-inflate)
  (:export #:ygo-card-name
           #:ygo-card-type
           #:ygo-card-frame-type
           #:ygo-card-race
           #:ygo-card-archetype
           #:ygo-card-attribute
           #:ygo-card
           #:ygo-card-misc-info
           #:ygo-set-name
           #:ygo-set-code
           #:ygo-set-rarity-code
           #:ygo-set-rarity
           #:ygo-set-edition
           #:ygo-set
           #:ygo-set-item
           #:ygo-linkmarker
           #:ygo-format
           ;; #:ygo-banlist-name
           ;; #:ygo-format-name
           ;; #:ygo-linkmarker-name
           #:ygo-banlist
           #:ygo-alternative-artwork
           #:ygo-price

           ;; Accessor Methods
           #:ygo-alternate-id-of
           #:ygo-archetype-of
           #:ygo-atk-of
           #:ygo-attribute-of
           #:ygo-ban-goat
           #:ygo-ban-ocg
           #:ygo-ban-tcg
           #:ygo-beta-id-of
           #:ygo-beta-name-of
           #:ygo-card-type-of
           #:ygo-code-of
           #:ygo-common-charity-format
           #:ygo-def-of
           #:ygo-desc-of
           #:ygo-downvotes-of
           #:ygo-duel-links-format
           #:ygo-edison-format
           #:ygo-edition-of
           #:ygo-frame-type-of
           #:ygo-goat-format
           #:ygo-has-effect
           #:ygo-is-staple
           #:ygo-konami-id-of
           #:ygo-level-of
           #:ygo-linkmarker-bottom
           #:ygo-linkmarker-bottom-left
           #:ygo-linkmarker-bottom-right
           #:ygo-linkmarker-left
           #:ygo-linkmarker-right
           #:ygo-linkmarker-top
           #:ygo-linkmarker-top-left
           #:ygo-linkmarker-top-right
           #:ygo-name-of
           #:ygo-ocg-date-of
           #:ygo-ocg-format
           #:ygo-ocg-goat-format
           #:ygo-passcode-of
           #:ygo-question-atk
           #:ygo-question-def
           #:ygo-race-of
           #:ygo-rarity-of
           #:ygo-scale-of
           #:ygo-set-code-of
           #:ygo-set-rarity-code-of
           #:ygo-speed-duel-format
           #:ygo-tcg-date-of
           #:ygo-tcg-format
           #:ygo-treated-as
           #:ygo-upvotes-of
           #:ygo-url-of
           #:ygo-views-of
           #:ygo-viewsweek-of
           #:ygo-amazon-price-of
           #:ygo-cardmarket-price-of
           #:ygo-coolstuffinc-price-of
           #:ygo-ebay-price-of
           #:ygo-tcgplayer-price-of
           #:ygo-price-of

           #:qty-of
           #:item-of
           #:variant-of
           #:sell-price-of
           #:opt-qty-of
           #:buy-price-of)
  (:documentation "New YGOProDeck database schema - classes."))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.ygoprodeck.methods
  (:use #:cl
        #:cl-deck-builder2.db
        #:cl-deck-builder2.models.generics
        #:cl-deck-builder2.models.ygoprodeck.classes
        #:cl-deck-builder2.models.ygoprodeck.fields)
  (:import-from #:cl-deck-builder2.models.registered-table
                #:registered-classes
                #:registry)
  (:export #:print-object
           #:split-code
           #:ygo-card
           #:ygo-card-by-name
           #:ygo-card-by-passcode
           #:ygo-card-names-by-deck-id
           #:ygo-card-names-from-list
           #:ygo-card-sets
           #:ygo-set
           #:ygo-set-by-id
           #:ygo-set-by-code
           #:ygo-set-by-name
           #:ygo-set-by-passcode
           #:ygo-select-set-item)
  (:documentation "New YGOProDeck database schema - methods."))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.ygoprodeck.cardinfo
  (:use #:cl)
  (:local-nicknames (#:v #:org.shirakumo.verbose))
  (:export #:cardinfo
           #:cardinfo-input
           #:cardinfo-output
           #:cardinfo-input-exists-p
           #:cardinfo-output-exists-p
           #:cardinfo-json
           #:cardinfo-list
           #:cardinfo-download
           #:cardinfo-cleanup
           #:cardinfo-convert
           #:cardinfo-update-and-cleanup))

(defpackage #:cl-deck-builder2.models.ygoprodeck.json
  (:use #:cl
        #:cl-deck-builder2.db
        #:cl-deck-builder2.toolkit
        #:cl-deck-builder2.models.generics
        #:cl-deck-builder2.models.ygoprodeck.fields
        #:cl-deck-builder2.models.ygoprodeck.cardinfo
        #:cl-deck-builder2.models.ygoprodeck.classes)
  (:local-nicknames (#:v #:org.shirakumo.verbose))
  (:export #:cardinfo-import))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.user
  (:use #:cl
        #:cl-deck-builder2.models.generics
        #:cl-deck-builder2.db)
  (:import-from #:cl-deck-builder2.models.registered-table
                #:registered-table-class)
  (:import-from :mito-auth
                :has-secure-password)
  (:export #:user
           #:name-of
           #:user-email-of
           #:user-roles-of

           #:role

           #:user-role
           #:user-role-user
           #:user-role-role

           #:user-admin-p
           #:user-verified-p

           #:create-user
           #:find-user
           #:create-role
           #:add-role))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.feedback
  (:use #:cl)
  (:import-from #:cl-deck-builder2.db
                #:create-dao)
  (:import-from #:cl-deck-builder2.models.registered-table
                #:registered-table-class)
  (:import-from #:cl-deck-builder2.models.user
                #:user)
  (:export #:feedback
           #:feedback-body-of
           #:feedback-user-of
           #:create-feedback))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This package doesn't touch the DB ... yet
(defpackage #:cl-deck-builder2.models.qr-code
  (:use :cl
   :cl-deck-builder2.db)
  (:local-nicknames (#:v #:org.shirakumo.verbose))
  (:import-from :cl-deck-builder2.toolkit
                :query-param)
  (:export :qr-settings
           :qr-string
           :qr-min-version
           :qr-ec-level
           :qr-encoding-mode
           :qr-mask-number
           :qr-to-plist
           :qr-generate))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.ydk
  (:use #:cl
        #:cl-deck-builder2.db
        #:cl-deck-builder2.models.generics
        #:cl-deck-builder2.models.registered-table
        #:cl-deck-builder2.toolkit)
  (:import-from #:cl-deck-builder2.models.category
                #:category)
  (:import-from #:cl-deck-builder2.models.ygoprodeck
                #:ygo-info)
  (:export #:ydk
           #:deck-item
           #:ydk-deck

           #:deck-id-of
           #:deck-kind-of
           #:deck-passcode-of
           #:ydk-created-by
           #:ydk-name-of
           #:ydk-id-of
           #:ydk-deck-delete-from
           #:ydk-deck-item-delete-from
           #:ydk-deck-delete-by-id
           #:ydk-deck-delete-by-name
           #:ydk-deck-by-id
           #:ydk-deck-by-name
           #:ydk-deck-info-by-id
           #:ydk-rename-deck
           #:ydk-add
           #:ydk-clear
           #:ydk-sync

           #:ydk-main-deck-of
           #:ydk-extra-deck-of
           #:ydk-side-deck-of
           #:ydk-category-of

           #:ydk-all
           #:ydk-concatenate
           #:ydk-unique
           #:ydk-query
           #:ydk-sorted

           #:ydk-delete
           #:ydk-delete-index

           #:ydk-table-ensure-exists
           #:ydk-table-drop
           #:ydk-table-delete
           #:ydk-table-select
           #:ydk-table-select-count

           #:ydk-to-kde)
  (:documentation "This model is just a thin wrapper around YDK format.

The YDK Format is like this:

    created by...
    #main
    <a series of passcodes>
    #extra
    <a series of passcodes>
    !side
    <a series of passcodes>

TODO CL-YDK + YDK-STORAGE-MIXIN?"))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Psuedo class for working with the SQLite database.
;; This will probably go away once we switch over to MariaDB.
(defpackage #:cl-deck-builder2.models.sqlite-schema
  (:use :cl
   :cl-deck-builder2.db)
  (:export #:sqlite-schema
           #:kind-of
           #:sql-of
           #:rootpage-of
           #:table-names))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defpackage #:cl-deck-builder2.models.constructed-decks
  (:use #:cl
        #:cl-deck-builder2.db
        #:cl-deck-builder2.toolkit
        #:cl-deck-builder2.models.generics
        #:cl-deck-builder2.models.registered-table
        #:cl-deck-builder2.models.ygoprodeck.classes
        #:cl-deck-builder2.models.ygoprodeck.methods)
  (:import-from #:cl-deck-builder2.models.category
                #:category)
  (:import-from #:cl-deck-builder2.models.ydk
                #:deck-item
                #:deck-id-of
                #:deck-passcode-of
                #:ydk-category-of
                #:ydk-created-by
                #:ydk-name-of
                #:ydk-deck)
  (:local-nicknames (#:v #:org.shirakumo.verbose))
  (:export #:constructed-deck
           #:constructed-deck-item
           #:constructed-deck-intermediate

           #:cdi-deck-item
           #:cdi-deck-set
           #:cdi-deck-set-item
           #:cdi-deck-condition
           #:cdi-deck-card

           #:constructed-deck-as-cdi-list

           ;; :deck-category-of
           ;; :deck-created-by
           ;; :deck-id-of
           :deck-name-of
           ;; :deck-sell-price
           :deck-sell-price-of
           :deck-sold
           ;; :ydk-deck-of
           ;; :ygo-card-of

           ;; #:sold-deck

           #:ydk-deck-pull-from-inventory
           #:find-any-invalid-qtys
           #:deck-to-pull-set-items-qty-as-alist
           #:deck-to-pull-desired-qty-as-alist
           #:subtract-desired-from-set-item-qty-as-alist
           #:valid-pull-p

           #:cdi-pull-from-inventory))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(uiop:define-package #:cl-deck-builder2.models
  (:use #:cl)
  (:use-reexport #:cl-deck-builder2.models.attachment
                 #:cl-deck-builder2.models.category
                 #:cl-deck-builder2.models.constructed-decks
                 #:cl-deck-builder2.models.feedback
                 #:cl-deck-builder2.models.qr-code
                 #:cl-deck-builder2.models.registered-table
                 #:cl-deck-builder2.models.sqlite-schema
                 #:cl-deck-builder2.models.user
                 #:cl-deck-builder2.models.ydk
                 #:cl-deck-builder2.models.ygoprodeck
                 #:cl-deck-builder2.models.ygoprodeck.fields
                 #:cl-deck-builder2.models.ygoprodeck.cardinfo
                 #:cl-deck-builder2.models.ygoprodeck.json
                 ;; TODO replace ygoprodeck with ygoprodeck2
                 #:cl-deck-builder2.models.ygoprodeck.classes
                 #:cl-deck-builder2.models.ygoprodeck.methods))
