#lang racket/base

; Floraverse generator database
(require
  json
  "../../base-generation/category.rkt"
  "calendar.rkt"
  "motto.rkt"
  "gender.rkt"
  "sex.rkt"
  "element.rkt"
  "geography.rkt"
  "species.rkt"
  "../phonagen.rkt"
  "trait.rkt"
  "ability.rkt"
  )

(provide
  ; Build generator from a path containing the different json files
  make-flora-generator
  ; Accessors to various parts of the generator
  flora-generator-path
  flora-generator-calendar
  flora-generator-mottos
  flora-generator-natures
  flora-generator-word-lists
  flora-generator-genders
  flora-generator-sexes
  flora-generator-elements
  flora-generator-geography
  flora-generator-species
  flora-generator-name
  flora-generator-traits
  flora-generator-abilities
  )

; Flora generator structure
(struct flora-generator
  (path ; path to the database directory
   calendar ; calendar informations, to generate dates
   mottos ; Motto generator
   natures ; Nature generator
   word-lists ; Generator of words from lists
   genders ; Dictionnary of genders
   sexes ; Dictionnary of sexes
   elements ; Dictionnary of magic elements
   geography ; Geographical informations
   species ; Species information
   name ; Name generator
   traits ; Traits generator
   abilities ; Abilities information
  ))

; Helper to retrieve the files
(define (load-json-file prefix data-dir file-name)
  (call-with-input-file (string-append prefix data-dir "/" file-name) read-json))

; Build flora generator from json files
(define (make-flora-generator prefix data-dir phonagen-file)
  (flora-generator
    data-dir
    (jsexpr->calendar (load-json-file prefix data-dir "calendar.json"))
    (jsexpr->motto-generator (load-json-file prefix data-dir "mottos.json"))
    (jsexpr->category-generator (load-json-file prefix data-dir "natures.json"))
    (jsexpr->category-generator (load-json-file prefix data-dir "word-lists.json"))
    (jsexpr->genders (load-json-file prefix data-dir "genders.json"))
    (jsexpr->sexes (load-json-file prefix data-dir "sexes.json"))
    (jsexpr->elements (load-json-file prefix data-dir "elements.json"))
    (jsexpr->geography (load-json-file prefix data-dir "geography.json"))
    (jsexpr->species-database (load-json-file prefix data-dir "species.json"))
    (jsexpr->phonagen (call-with-input-file (string-append prefix phonagen-file) read-json))
    (jsexpr->traits-generator (load-json-file prefix data-dir "traits.json"))
    (jsexpr->ability-database (load-json-file prefix data-dir "abilities.json"))
  ))
