;; Toy Drive - Toy collection for orphans
;; Halal - bringing joy to children
(define-constant CONTRACT-OWNER tx-sender)
(define-constant ERR-AUTH (err u401))
(define-data-var drive-count uint u0)
(define-data-var total-toys uint u0)
(define-map toy-drives uint { organizer: principal, toys-collected: uint, toys-given: uint, status: (string-ascii 20) })
(define-map toy-donors { drive-id: uint, donor: principal } uint)
(define-public (create-drive)
(let ((id (+ (var-get drive-count) u1)))
(map-set toy-drives id { organizer: tx-sender, toys-collected: u0, toys-given: u0, status: "active" })
(var-set drive-count id) (ok id)))
(define-public (donate-toys (drive-id uint) (toys uint))
(let ((d (unwrap! (map-get? toy-drives drive-id) (err u404))))
(map-set toy-donors { drive-id: drive-id, donor: tx-sender } toys)
(map-set toy-drives drive-id (merge d { toys-collected: (+ (get toys-collected d) toys) }))
(var-set total-toys (+ (var-get total-toys) toys)) (ok toys)))
(define-public (give-toys (drive-id uint) (count uint))
(let ((d (unwrap! (map-get? toy-drives drive-id) (err u404))))
(asserts! (is-eq tx-sender (get organizer d)) ERR-AUTH)
(map-set toy-drives drive-id (merge d { toys-given: (+ (get toys-given d) count) })) (ok count)))
(define-read-only (get-drive (id uint)) (map-get? toy-drives id))
(define-read-only (get-stats) (ok { drives: (var-get drive-count), toys: (var-get total-toys) }))