(define-map batches uint {creator: principal, escrow-count: uint, total-amount: uint, status: (string-ascii 20)})
(define-map batch-escrows {batch-id: uint, index: uint} uint)
(define-data-var batch-count uint u0)
(define-read-only (get-batch (id uint)) (map-get? batches id))
(define-public (create-batch (total-amount uint))
(let ((id (var-get batch-count)))
(map-set batches id {creator: tx-sender, escrow-count: u0, total-amount: total-amount, status: "active"})
(var-set batch-count (+ id u1))
(ok id)))
(define-public (add-to-batch (batch-id uint) (escrow-id uint))
(match (map-get? batches batch-id)
b (begin
(map-set batch-escrows {batch-id: batch-id, index: (get escrow-count b)} escrow-id)
(map-set batches batch-id (merge b {escrow-count: (+ (get escrow-count b) u1)}))
(ok true))
(err u404)))