 begin mint 9
(define-public (claim-nine)
  (begin
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (ok true)))
;; end mint 9

 Set public sale flag
(define-public (flip-private-sale)
  (begin
    (asserts! (is-eq tx-sender (var-get admin)) ERR-NOT-AUTHORIZED)
    ;; Disable the Public sale
    (var-set sale-active false)
    (var-set private-sale-active (not (var-get private-sale-active)))
    (ok (var-get private-sale-active))))

;; Set public sale flag
(define-public (flip-sale)
  (begin
    (asserts! (is-eq tx-sender (var-get admin)) ERR-NOT-AUTHORIZED)
    (var-set private-sale-active false)
    (var-set sale-active (not (var-get sale-active)))
    (ok (var-get sale-active))))

(define-read-only (get-sale-status)
  (list 
    (and (var-get private-sale-active) (>= block-height (var-get private-target-block-height)))  
    (and (var-get sale-active) (>= block-height (var-get public-target-block-height)))
  )
)

(define-read-only (get-private-target-block-height)
  (var-get private-target-block-height)
)

(define-read-only (get-public-target-block-height)
  (var-get public-target-block-height)
)

(define-read-only (get-private-presale-balance (account principal))
  (default-to u0
    (map-get? private-presale-count account)))

(define-read-only (get-public-balance (account principal))
  (default-to u0
    (map-get? public-sale-count account)))

;; Internal - Mint NFT using Mintpass mechanism
(define-private (private-mintpass-mint (new-owner principal))
  (let ((mint-count (get-private-presale-balance new-owner)))
    (asserts! (var-get private-sale-active) ERR-SALE-NOT-ACTIVE)
    (asserts! (>= block-height (var-get private-target-block-height)) ERR-BEFORE-MINT-TIME)
    (asserts! (> mint-count u0) ERR-NO-MINTPASS-REMAINING)
    (map-set private-presale-count
              new-owner
              (- mint-count u1))
    (mint new-owner) 
  )
)

;; Internal - Mint public sale NFT
(define-private (public-mint (new-owner principal))
  (let ((mint-count (get-public-balance new-owner)))
    (asserts! (var-get sale-active) ERR-SALE-NOT-ACTIVE)
    (asserts! (>= block-height (var-get public-target-block-height)) ERR-BEFORE-MINT-TIME)
    (mint new-owner)
  )
)

;; update pre-sale counts
(define-public (set-private-wl (address principal) (limit uint))
  (begin
    (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-NOT-AUTHORIZED)
    (map-set private-presale-count address limit)
    (ok true)
  )
)

(define-public (bulk-set-private-wl (addresses (list 1000 principal)) (limits (list 1000 uint)))
  (begin
    (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-NOT-AUTHORIZED)
    (print (map set-private-wl addresses limits))
    (ok true)
  )
)

(define-public (set-public-target-block-height (target uint))
  (begin
    (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-NOT-AUTHORIZED)
    (var-set public-target-block-height target)
    (ok true)
  )
)

(define-public (set-private-target-block-height (target uint))
  (begin
    (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-NOT-AUTHORIZED)
    (var-set private-target-block-height target)
    (ok true)
  )
)

;; ###### BEGIN: commissions template code ##################################################
(define-data-var secondary-commission uint u250)

(define-public (pay (id uint) (price uint))
    (if (> (var-get secondary-commission) u0)
        (begin  
                (try! (stx-transfer? (/ (* price (var-get secondary-commission)) u10000) tx-sender (var-get commission-address)))
                ;; total of 5% = u500
                  (try! (stx-transfer? (/ (* price u350) u10000) tx-sender 'SP7NW9XVEG45SW1367SAHHZG67BFA4GMA9DVGZ0F))
  (try! (stx-transfer? (/ (* price u150) u10000) tx-sender 'SP3KAPN7TWS0H7CHMTPJ2DWWX9AGPJ821TMHGMDGX))

                (ok true)
        )
        (ok true)
    )
)

(define-public (set-commission (amount uint))
    (begin
        (asserts! (is-eq tx-sender (var-get commission-address)) ERR-NOT-AUTHORIZED)
        (var-set secondary-commission amount)
        (ok true)
    )
)

(define-public (set-commission-address (address principal))
    (begin
        (asserts! (is-eq tx-sender (var-get commission-address)) ERR-NOT-AUTHORIZED)
        (var-set commission-address address)
        (ok true)
    )
)

(define-public (get-commission)
    (ok (var-get secondary-commission))
)

(define-public (get-commission-address)
    (ok (var-get commission-address))
)
;; ###### END: commission template code ##################################################

(begin
  (try! (set-private-wl 'SP14PSP8WWCE42Z714JAGTC4AZFSJAWY150PQPP5R uundefined))
  (try! (set-private-wl 'SP3KAPN7TWS0H7CHMTPJ2DWWX9AGPJ821TMHGMDGX uundefined))
  (try! (set-private-wl 'SP2E6976SAHE74X64W8Q71YC3QEH4BDQA075PJSHW uundefined))
  (try! (set-private-wl 'SP35EWH2ZV6TX3QR65HEXR22HVKZ16NW9ZCAZW1P3 uundefined))
  (try! (set-private-wl 'SP2DWEVQD0J6R463AW0BEBMR6X197PG5XV5Q8MMT4 uundefined))
  (try! (set-private-wl 'SP26K3JHN9YP2QDST5MFC3GYQY6V4Z523AGHANHMF uundefined))
  (try! (set-private-wl 'SP7NW9XVEG45SW1367SAHHZG67BFA4GMA9DVGZ0F uundefined))
  (ok true)
)
