(impl-trait 'ST2PABAF9FTAJYNFZH93XENAJ8FVY99RRM4DF2YCW.nft-trait.nft-trait)

(define-non-fungible-token fsda uint)

(define-constant MAX (uint 23131))
(define-constant CONTRACT-CREATOR tx-sender)

(define-constant ERR-NOT-AUTHORIZED (err u0))

(define-data-var token-uri (string-ascii 256) "")
(define-data-var last-id uint u0)

(define-public (transfer (token-id uint) (sender principal) (recipient principal))
  (begin
    (asserts! (is-eq tx-sender sender) ERR-NOT-AUTHORIZED)
    (nft-transfer? fsda token-id sender recipient)))

(define-read-only (get-owner (token-id uint))
  (ok (nft-get-owner? fsda token-id)))

(define-read-only (get-last-token-id)
  (ok (var-get last-id)))

(define-read-only (get-token-uri (token-id uint))
  (ok some(var-get token-uri)))

(define-public (mint (token-id uint) (recipient principal))
  (begin
    (asserts! (is-eq tx-sender CONTRACT-CREATOR) ERR-NOT-AUTHORIZED)
    (try! (mint recipient token-id))
    (var-set last-id (+ u1 (var-get last-id)))
    (ok true)))

(define-public (set-token-uri (new-token-uri (string-ascii 256)))
  (begin
    (asserts! (is-eq tx-sender CONTRACT-OWNER) (err ERR-NOT-AUTHORIZED))
    (var-set token-uri new-token-uri)
    (ok true)))