;; Ruqyah Center - Spiritual healing center
;; Halal - Quranic healing
(define-constant CONTRACT-OWNER tx-sender)
(define-constant ERR-AUTH (err u401))
(define-constant ERR-NONE (err u404))
(define-data-var session-count uint u0)
(define-map practitioners principal { name: (string-utf8 100), sessions: uint, active: bool })
(define-map healing-sessions uint { practitioner: principal, patient: principal, method: (string-ascii 20), fee: uint, completed: bool })
(define-public (register-practitioner (name (string-utf8 100)))
(begin (asserts! (is-eq tx-sender CONTRACT-OWNER) ERR-AUTH)
(map-set practitioners tx-sender { name: name, sessions: u0, active: true }) (ok true)))
(define-public (book-session (practitioner principal) (method (string-ascii 20)) (fee uint))
(let ((id (+ (var-get session-count) u1)) (p (unwrap! (map-get? practitioners practitioner) ERR-NONE)))
(asserts! (get active p) ERR-NONE)
(try! (stx-transfer? fee tx-sender practitioner))
(map-set healing-sessions id { practitioner: practitioner, patient: tx-sender, method: method, fee: fee, completed: false })
(var-set session-count id) (ok id)))
(define-public (complete-session (id uint))
(let ((s (unwrap! (map-get? healing-sessions id) ERR-NONE)) (p (unwrap! (map-get? practitioners (get practitioner s)) ERR-NONE)))
(asserts! (is-eq tx-sender (get practitioner s)) ERR-AUTH)
(map-set healing-sessions id (merge s { completed: true }))
(map-set practitioners tx-sender (merge p { sessions: (+ (get sessions p) u1) })) (ok true)))
(define-read-only (get-practitioner (who principal)) (map-get? practitioners who))
(define-read-only (get-session (id uint)) (map-get? healing-sessions id))
(define-read-only (get-session-count) (ok (var-get session-count)))