;; SatGuard Pool Delegate - delegate pool management
(define-constant err-owner (err u530))
(define-constant err-nf (err u531))
(define-constant err-unauth (err u532))
(define-map operators {pid: uint,op: principal} {sa: uint,by: principal})
(define-map pool-admins {pid: uint} {admin: principal})
(define-read-only (is-operator (pid uint) (op principal)) (is-some (map-get? operators {pid: pid,op: op})))
(define-read-only (get-pool-admin (pid uint)) (map-get? pool-admins {pid: pid}))
(define-public (set-pool-admin (pid uint))
(let ((pool (unwrap! (contract-call? .insurance-pool get-pool pid) err-nf)))
(asserts! (is-eq tx-sender (get cr pool)) err-owner)
(map-set pool-admins {pid: pid} {admin: tx-sender})
(print {e: "pool-admin-set",pid: pid,admin: tx-sender})
(ok true)))
(define-public (set-operator (pid uint) (op principal))
(let ((pa (unwrap! (map-get? pool-admins {pid: pid}) err-nf)))
(asserts! (is-eq tx-sender (get admin pa)) err-owner)
(map-set operators {pid: pid,op: op} {sa: block-height,by: tx-sender})
(print {e: "operator-set",pid: pid,op: op})
(ok true)))
(define-public (remove-operator (pid uint) (op principal))
(let ((pa (unwrap! (map-get? pool-admins {pid: pid}) err-nf)))
(asserts! (is-eq tx-sender (get admin pa)) err-owner)
(map-delete operators {pid: pid,op: op})
(print {e: "operator-removed",pid: pid,op: op})
(ok true)))