#lang racket/base

(require
  "../../base-generation/random.rkt"
  "../../lang/case.rkt")

; Model and generation of mottos
(provide
  jsexpr->motto-generator motto-generate)

; Motto generator structure
(struct motto-generator
  (prefix
   prefixable
   unprefixable))

; Build a motto generator structure from a json expression
(define (jsexpr->motto-generator js)
  (motto-generator
    (hash-ref js 'prefix)
    (hash-ref js 'prefixable)
    (hash-ref js 'unprefixable)))

; Generate a motto
(define (motto-generate gen)
  (if (random:boolean)
      (random:from-list (motto-generator-unprefixable gen))
      (case:upcase-1st
        (string-append
          (random:from-list (motto-generator-prefix gen))
          (random:from-list (motto-generator-prefixable gen))))))
