;; Storage
(define-map presale-count principal uint)

;; Define Constants
(define-constant mint-price u70000000)
(define-constant CONTRACT-OWNER tx-sender)
(define-constant ERR-NOT-AUTHORIZED (err u401))
(define-constant ERR-SALE-NOT-ACTIVE (err u500))
(define-constant ERR-NO-MINTPASS-REMAINING (err u501))

;; Define Variables
(define-data-var mintpass-sale-active bool false)
(define-data-var sale-active bool false)

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

;; Public get pre sale status
(define-read-only (get-presale-status)
  (var-get mintpass-sale-active))

;; Public get public sale status
(define-read-only (get-publicsale-status)
  (var-get sale-active))

;; Claim a new NFT
(define-public (claim)
  (if (var-get mintpass-sale-active)
    (mintpass-mint tx-sender)
    (public-mint tx-sender)))

(define-public (claim-two)
  (begin
    (try! (claim))
    (try! (claim))
    (ok true)))

(define-public (claim-three)
  (begin
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (ok true)))

(define-public (claim-four)
  (begin
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (ok true)))

(define-public (claim-five)
  (begin
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (try! (claim))
    (ok true)))

;; Internal - Mint NFT using Mintpass mechanism
(define-private (mintpass-mint (new-owner principal))
  (let ((presale-balance (get-presale-balance new-owner)))
    (asserts! (> presale-balance u0) ERR-NO-MINTPASS-REMAINING)
    (map-set presale-count
              new-owner
              (- presale-balance u1))
  (contract-call? .sol-townsfolk-nft mint new-owner)))

;; Internal - Mint public sale NFT
(define-private (public-mint (new-owner principal))
  (begin
    (asserts! (var-get sale-active) ERR-SALE-NOT-ACTIVE)
    (contract-call? .sol-townsfolk-nft mint new-owner)))

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

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

(as-contract (contract-call? .sol-townsfolk-nft set-mint-address))

;; Mintpass Addresses
(map-set presale-count 'SP262H5HJMEY1MAC7X3K5K28VQARC8CB4NVHXR6T7 u5)
(map-set presale-count 'SPDXC0NM3YQDHV1HN3V9P5Y4P26QWY709NB86EYB u5)
(map-set presale-count 'SP2AYJHP9H3JM3T26ZBW0SKBCXJ9S4JW03VQBP7K1 u5)
(map-set presale-count 'SP328RRCE6B3DK3NJR01C2QHVVHXAF9WY9CVV36QD u5)
(map-set presale-count 'SP3EYT7KF5ERWQFTWW3SWHS8QRYBNSMRZ7JW73YXR u5)
(map-set presale-count 'SPTAM15MHVE6FAX7Q07TQ9QBSS5XCQXM26G4KET4 u5)
(map-set presale-count 'SP4T1A2BNKJMFBY7JNXRKTFYJGTNHW5GJ1W1BBBE u5)
(map-set presale-count 'SP606Y9VBE29GX2PGFR41NTE86DDXPW3C7DX7T8H u5)
(map-set presale-count 'SP3W5KN5XC7RQ5M0TMFGEZANE4P80Z7KQF1PJJB55 u5)
(map-set presale-count 'SP2MDEE7BMXWTNST6PKE8MGP2EWD6412ZNPTYMQ5S u5)
(map-set presale-count 'SP3HYFVG35TW1RF47N6RKYYDNPX6T47J6ZJB3B4PE u5)
(map-set presale-count 'SP3JPR7XNR60AMBBEZAGF1YHRSFY1JCKE14HBKGTY u5)
(map-set presale-count 'SP1MFKQM507CF8JT5SHYX992BHXC4Y5XY4WK3ZCMC u5)
(map-set presale-count 'SP1A37EMPF9HYESQW5QZJ56EMQGD5SYBTBMHN9SDJ u5)
(map-set presale-count 'SPHK8A7P61C6ASWKYDX1PCDX9YA54DKVJN49EXGJ u5)
(map-set presale-count 'SPJRW4D4JACQQQQ5DK09P1K7M2TE8PGZJ638HCW1 u5)
(map-set presale-count 'SPCP6QYQG399SWCF2TVAFHVHN302TB3ABRTWHPEH u5)
(map-set presale-count 'SPQY88E87FNMP1NTY2YQ7X5DPTVY810PS8T6D2Y3 u5)
(map-set presale-count 'SPPZ2SNVDBKSHZDQ2HBBVMB5HEHAXRC3T8CQ35EA u5)
(map-set presale-count 'SPXZ0GWQTMGQ860MGG86PNMFJNHJ2NWJSWJWGM0K u5)
(map-set presale-count 'SPTETNN57BDV0X796ZVW41B5VVN99JQRDH68Z5W6 u5)
(map-set presale-count 'SP1HZ3M9D4F19D80HZC66R93XKQ18PRT70KYFCF8A u5)
(map-set presale-count 'SP2P8QYQX5PMKVBXQ9FWK8F96J8DJXXW7NB7AA5DT u5)
(map-set presale-count 'SP32CF0E78JNPK0HYDTH3CCZ8FN76PFX5W0FYBN20 u5)
(map-set presale-count 'SP3YDKTXXDNE6MR64YDW494N39PB7S796M8EC4GEB u5)
(map-set presale-count 'SP23NXVJWQARSPF1K3TD73MHVJE4EFV9V58GXHT73 u5)
(map-set presale-count 'SPBBCZQP08M6FQJE2PPXQTETC0MT0DRZCAWXT3MG u5)
(map-set presale-count 'SP27A09VG1SH1J8Z76NXHBGKB0ZWSBZ99DRGAC8NB u5)
(map-set presale-count 'SP158378PVRA077MC9851WTVSF7G3MES99HPJ26DW u5)
(map-set presale-count 'SP3TNWFMV4PAH9Q5M5Z7XKN5Y7AM9QWEGAWK13K24 u5)
(map-set presale-count 'SP2WGW1GPCYM0KXEFW3EK9CEW8ZWRRDPM7GS7DS6F u5)
(map-set presale-count 'SP4JRVAABXMXVNSA023C4KW3MEHND6BGRPQK51NB u5)
(map-set presale-count 'SP1XAR0A0J2AFWXQXCJ07SPV3TSZV2BCQQAQ6H5B5 u5)
(map-set presale-count 'SPF4FR0X9Q4PAF6KENDD3NVAGQTM8A830A4F96YG u5)
(map-set presale-count 'SP79JMAGQVWMVWRXG2AE5GF8Z27VF1W4KZ3J03WG u5)
(map-set presale-count 'SP2M63YGBZCTWBWBCG77RET0RMP42C08T73MKAPNP u5)
(map-set presale-count 'SP2CZ9HX0D766VBDFQJEZS3G291PPKSHKS7VFAGAJ u5)
(map-set presale-count 'SP3QJ41PARX6F6B4H56JZ272ANK0TRJ9J2VFBVY1D u5)
(map-set presale-count 'SPJ52DQFJVJACKHY0QX5DRE559MBCXWTSGNBN76V u5)
(map-set presale-count 'SP1M0JJQTJ8JTCN9MJXPZTS5ARD9V1HH2R98865F7 u5)
(map-set presale-count 'SP1P637C9NB6GSK9TY8AT8SN3QKH1WSV5ZVCZZSKS u5)
(map-set presale-count 'SP3MEYWYZY6J0BJJYFMXQVAC54BBXVZA9P9DE0KKQ u5)
(map-set presale-count 'SPDAV1G8FQ0TMEWKVE0A9WS8RNDJ7K808X2MY22E u5)
(map-set presale-count 'SP3JJC9CVH2251JC0B4QTPS661H6JNTA2P9E6HA6N u5)
(map-set presale-count 'SP3EFRKPP5K22S0P1G6X4WB694HC6CVX5KKZDGAK5 u5)
(map-set presale-count 'SPGR0ZRYE9P63PXGEE0KH1888JHNBEXDFRCVG0HC u5)
(map-set presale-count 'SPPRYDX8ZC6B1937TBQMRJDPXFZX6ST5X87N1TWT u5)
(map-set presale-count 'SP1SXFE323XBDFEK6D5BV7P20BD3B4Y8W1RFN759H u5)
(map-set presale-count 'SP2Q1SZSETS27AZ9FE0BH6C6B7MVC25E4N6C2VE7D u5)
(map-set presale-count 'SP1FR2M102H4DE4DH96R4D29RC8AGQZG5D5Y4S7CH u5)
(map-set presale-count 'SP2408C7PANMGT3G1F4EJ2WS3DW9FGRKV5K1P2A88 u5)
(map-set presale-count 'SP342MMZRDFSC556F193N76D87SCTYX7SSHD8H3XD u5)
(map-set presale-count 'SP3A6SRWC0295MPY00805CZBWSF1TAY8DWMR05XFM u5)
(map-set presale-count 'SP14814KM6CBCJZMD15JJ58Q3E2S3NCB6SDXM8C79 u5)
(map-set presale-count 'SP4QA0NHP03T3T9GJKR5KEA7VQ2KNSXRK5JC74NG u5)
(map-set presale-count 'SP1CVHMVJ5KWW1DPJV7X7CJ9QW2FCYJ3KR001WK9J u5)
(map-set presale-count 'SPM1Q7YG18378H6W254YN8PABEVRPT38ZCY01SJD u5)
(map-set presale-count 'SP2E03GHWY145XMFDTHX4Z913EADP4RMZ0P0DCTE9 u5)
(map-set presale-count 'SP23RS2V3BAWHNQ3RHVZHK10F51RA99C1FHQKY9QH u5)
(map-set presale-count 'SP1S1YNCTPCJ37HETC516KANQYA9G47GDBN0N7DS4 u5)
(map-set presale-count 'SP3ZY51K23M753B7S2CG823Y47EE80RC3ZMYJ78X u5)
(map-set presale-count 'SP2AWN2MFRTK2HQ2KAJWBNS9V2AQRM9G2F8GTQNV2 u5)
(map-set presale-count 'SP3BJ4GDXYMBRS42NJNVE271YPAPYTF28T9722GHJ u5)
(map-set presale-count 'SP3XM3WZDJ6YGA5ANTSABJ6XRFPST7Y2C5KH0Z1W5 u5)
(map-set presale-count 'SP2EQXAKMCK9H3RBG5W26BVTCY46RVHJFH9VBPE7R u5)
(map-set presale-count 'SP38CJGXS4JPJ14G1VJ0JYBHCER3HJB6TWE04ZE7Z u5)
(map-set presale-count 'SP2MG753Q0B9HGCS9BMJEH1C1N8BVBXSK7B5KCTAN u5)
(map-set presale-count 'SP0CW9AB35MW3EXKG35N1ZG563GZFXW1PYMPKGNE u5)
(map-set presale-count 'SP3ZMWZGPFBXTDW1FHET6XYD10S4Q61D0TGEP6RTE u5)
(map-set presale-count 'SP2891F1DM9QJ14F711C62NQS3RQG4VFV6ZTEEN60 u5)
(map-set presale-count 'SP1999G9FRT3G107D8Z8TJ7R226VTNDVVAYZ53VXF u5)
(map-set presale-count 'SP3R4072V0KK5ATBVJ829F9MDD8XYA8YQHFCBN4RD u5)
(map-set presale-count 'SP3N1T4G0B0E54F6MAWT9D3E5TJA2EE0MSVAQ8EA6 u5)
(map-set presale-count 'SP3498Y9KAVZSXX82B4GRWMHK19T489TGYDFD8AFJ u5)
(map-set presale-count 'SPMWVJWPNA60MSNF14PR9C0G65GCDM4GXDH8CJE5 u5)
(map-set presale-count 'SP2HK7J6617VBSKXQGZWMXP2R64MMDX3S54M0S1Q6 u5)
(map-set presale-count 'SPJCSG2ZJD95JR4QG9Z0EP786WN7T3CAF7GKBD01 u5)
(map-set presale-count 'SP3A5VJWA3CH4BM7W08APVJKJ8MQ7PXXFACWAYA2J u5)
(map-set presale-count 'SP3ZJPSRZKYFZRFCNKWRP30RERBB7Z7B5HPEKVJHX u5)
(map-set presale-count 'SP28317JGN1WCMYE4TKH06CVDXAGFRG1TK98VRHZH u5)
(map-set presale-count 'SP2F40S465JTD7AMZ2X9SMN229617HZ9YB0HHY98A u5)
(map-set presale-count 'SPT8MA3H81X02BKEFX2WF7FJKV2G1FZX1SFR6HX2 u5)
(map-set presale-count 'SPAPQQJDYSQM184CMN34YGZENJM0H6ZN9N1204RK u5)
(map-set presale-count 'SP2F44DVEQTFTPB1MGA9CSHCVNMWHZCDR99VPMJ8Y u5)
(map-set presale-count 'SPDPX0F5AV4KF3VN7FYP3H9BJ83CWKT1V5H3RJCF u5)
(map-set presale-count 'SPYAX2RNZA18KQA8Y0S5G393QBE8SWPNZ6R08XNH u5)
(map-set presale-count 'SP3HXZSBYYAE8PJR8P0VVX4HV128NBYB2T6XJ89N8 u5)
(map-set presale-count 'SP28YEDDDBM8GT23KVS9HEEGVRD4X35H542K100SC u5)
(map-set presale-count 'SPR35JC5BGKTN20GJAKRZJDM1P8J81NZSHZ40AV7 u5)
(map-set presale-count 'SPTQGNAH2NQN9QVPZ9H39DS3V6AF8EZ7R45TNEW5 u5)
(map-set presale-count 'SP3YSS74QDCSHYJCEQ69559T3YMRRWT4FXK1XBF6Z u5)
(map-set presale-count 'SP19B1VKRR79SBPVSQX1PDM2DJ0Y2MVA40MWC1BTF u5)
(map-set presale-count 'SP2F1QFS7H3GFNGBX4CRY9KRXGBSABQSVQTXANQ1Y u5)
(map-set presale-count 'SP17NZ4FXJAKJYM3976YT216ZTJVMJ6XACRB089XH u5)
(map-set presale-count 'SPS2RBYAXSCXMVPYXSG724CFY4W2WA2NPG44V191 u5)
(map-set presale-count 'SP3G9BMCJ0858Y68MM35R6HA0WAZDNYXWZBN4RYK1 u5)
(map-set presale-count 'SP1QVY5ZFXHK66K5YJG166X9VV7W6DDWVC7V2NWD1 u5)
(map-set presale-count 'SP3QPJQ0HCK0MZ25GWR88EWK686G0QP06XEYJ7SSB u5)
(map-set presale-count 'SP17J97CMQWPCFRE1HYKHBCFCW68WCM7W29P3FAG4 u5)
(map-set presale-count 'SP2HVX8YRZMBV71NRQ3CT3M03AM9VWJ30TZ5XX7XR u5)
(map-set presale-count 'SPM7VV57ACHHFQQ65EHEWJ279412VZ4N20FXFN8X u5)
(map-set presale-count 'SP1N5GPTCG9QW5XNNE4PHBAGM2T41BG9AMCDT0HB3 u5)
(map-set presale-count 'SPZG4Z9K35TF0J0PJ36K5VQTRCH0QRV54FSK0CFR u5)
(map-set presale-count 'SP2KJC2WBNJPGVRB0GG30666PQW96MAKH7YWGPWB0 u5)
(map-set presale-count 'SPN9SQPATME5FN0JGHHGP9MW1WVW26663D5YN2SS u5)
(map-set presale-count 'SP2R3CHRAP1HE4M64X1NZXHZT41JG3XGNHJW4HX2W u5)
(map-set presale-count 'SP1MCT54R5W04CJP04T3A79A2EB7K5D7RB3PT1YJ2 u5)
(map-set presale-count 'SPMPV5BSPVN9E287S0XEV8T39W9BPNDRGTM2KA5S u5)
(map-set presale-count 'SP3J3PS3CFGHEDQHEJNZQPDB3NV85NP290PRR83N2 u5)
(map-set presale-count 'SP1J4SFHSMMT5Z0PG3WDD1TNGZVCWMB5QBYHNFECG u5)
(map-set presale-count 'SP2791RKSYJJ39MVHC09J8NARWBMK5G9C79EJB0RV u5)
(map-set presale-count 'SP2ZD78CEHCFPJ71SB8R0EK0ZMVAGB3NTHK947F06 u5)
(map-set presale-count 'SPZ5DJGRVZHXEEEYYGWEX84KQB8P69GC715ZRNW1 u5)
(map-set presale-count 'SP1C0J8MDSQ67N2AADXTTDKM8SAR1JV3VY8DS25RG u5)
(map-set presale-count 'SP1K6W1QST3KKJHM4KGG2BN2WZQTD86PC8H9STN1B u5)
(map-set presale-count 'SP9227STGNCZPRTP2T2G3S02M7XB5ENAQB1J82FA u5)
(map-set presale-count 'SP3MPTWZFFS12C2GKSABZVAMY7NEBCWG2JAYRB7W3 u5)
(map-set presale-count 'SP3C5W9RSSYG3SVP192DCQY4Z2WQWPJ9YEERKTPSY u5)
(map-set presale-count 'SP2HV9HYWZRAPTCC10VXCK72P3W4F9NDB8E1HBEZH u5)
(map-set presale-count 'SP14E544B2FY8BSKTV5V7W8NCRYX2B7NXRQ7B7NJ9 u5)
(map-set presale-count 'SP18V7NZHXPQKRNBYAF5WGBV79PDY6XMDNHMZSW4R u5)
(map-set presale-count 'SP22YMD1THMGYKDVRCD48EKKDA6HDFPCNQQ4HNMGZ u5)
(map-set presale-count 'SPGYN0JFKZVEKB6KE4X5YTZATPG0M42A0Y1F8DMG u5)
(map-set presale-count 'SP3F0KB3SEBMRHWMSHYWFP2PKDX7NEK6405VP4MQA u5)
(map-set presale-count 'SPB6QWYFHZK0V7HNQGPK2HPBAQG0QST173HB3XT1 u5)
(map-set presale-count 'SP3ST6K5W36V2MTSNYYXE56SCXR7DGTW9N4NMZHYV u5)
(map-set presale-count 'SPZJSY1EQ6P4KMX1NX5CDFYJBEPWECFM4V58XB2G u5)
(map-set presale-count 'SP1CMFJW9J8WN7R2XJ26AC90AARGW68R1CWNYDANC u5)
(map-set presale-count 'SP301YB8MT9AW8P7RJ2GFN2BXVDHRJYJXTT5905SW u5)
(map-set presale-count 'SP30KD0JV9B3XX6DSPXSH90J621R7VBSSY2GNBC26 u5)
(map-set presale-count 'SP6CRZ19K5YTT64V8FGD5XTM6JCSP0MP1NVW40RJ u5)
(map-set presale-count 'SP1NBCK2JP3KNCHGGM8FGWPT7VFWSCBAXGMJ1WMZB u5)
(map-set presale-count 'SP18QG8A8943KY9S15M08AMAWWF58W9X1M90BRCSJ u5)
(map-set presale-count 'SP1B7FFVFHHBCB466DVJR02BQ7PS9TNW02YA29DR3 u5)
(map-set presale-count 'SP3ZVNKKNE596PZG97BTC9REHV91T6PFMXSVJEGZP u5)
(map-set presale-count 'SP1RQZCECRGR5W7J9PBX6TGF7Q0JN923E47W22KN7 u5)
(map-set presale-count 'SPGC8HSBZMGCDRD13BT5ESTJYWS412B21DZZ1P4J u5)
(map-set presale-count 'SP3NH76GQ6M070SEMXE1PHM1GW9A5GKTJME2S8Y4H u5)
(map-set presale-count 'SP2HX7247FTWB9FEM3J5CKJ3H3FKZ51C4D3XABFT u5)
(map-set presale-count 'SP2QYNBJSZDX7M8T1HHFKT11H9GVJ8VR3NHM73S0J u5)
(map-set presale-count 'SP1CCC68DRYZZKMPAZPWKE3VP2R7YSVN9DZJG86Y8 u5)
(map-set presale-count 'SP6K8CTMC52XBCNG9TRCF3JBE76S2BFYS985DANQ u5)
(map-set presale-count 'SP3JHYR2QFMQ8Z8NPHF6XH9B350JSZPTG0ZKYENPF u5)
(map-set presale-count 'SPX0FKCZ2QNS7AWYT95HQ89S1YGEEY89AYG8ASZ4 u5)
(map-set presale-count 'SP30K0ZAXC0GP3CXX68QCDPRWRPH1F98EEN13TYC1 u5)
(map-set presale-count 'SP3P8C22C8QEJJTCQQ3V80CBFMKDZQRK1P8MM68KJ u5)
(map-set presale-count 'SP1D3Y8A2VVD2W98VFXCG5AXRYX5PJBBEMV1YPKF1 u36)