;; ramadan-goal -- Ramadan personal goals tracker
(define-constant CONTRACT-OWNER tx-sender)
(define-constant ERR-NONE (err u404))
(define-data-var goal-count uint u0)
(define-map goals uint { user: principal, category: (string-ascii 20), target: uint, progress: uint, year: uint, completed: bool })
(define-map user-goals principal uint)
(define-public (set-goal (category (string-ascii 20)) (target uint) (year uint))
(let ((id (+ (var-get goal-count) u1))
(prev (default-to u0 (map-get? user-goals tx-sender))))
(var-set goal-count id)
(map-set goals id { user: tx-sender, category: category, target: target, progress: u0, year: year, completed: false })
(map-set user-goals tx-sender (+ prev u1))
(ok id)))
(define-public (update-progress (id uint) (increment uint))
(let ((g (unwrap! (map-get? goals id) ERR-NONE)))
(let ((new-progress (+ (get progress g) increment)))
(map-set goals id (merge g { progress: new-progress, completed: (>= new-progress (get target g)) }))
(ok new-progress))))
(define-read-only (get-goal (id uint)) (map-get? goals id))
(define-read-only (get-user-goal-count (addr principal)) (default-to u0 (map-get? user-goals addr)))
(define-read-only (get-total-goals) (var-get goal-count))