Skip to content

Custody Lifecycle State Machine #60

@amina69

Description

@amina69

Implement Custody Lifecycle State Machine

Labels:
backend domain-logic state-machine

🎯 Goal

Enforce valid lifecycle transitions for Custody.status.

Custody must not be arbitrarily reopened or reversed.

🧠 Context

Custody represents temporary responsibility over a pet (rehoming, temporary care, etc).

It affects:

Pet availability

Trust scoring

Movement history

Invalid transitions could corrupt the pet movement timeline.

📊 Valid Custody Flow
ACTIVE

RETURNED
Alternative flows
ACTIVE → CANCELLED
ACTIVE → VIOLATION
❌ Invalid Transitions

RETURNED → ACTIVE

CANCELLED → ACTIVE

VIOLATION → ACTIVE

RETURNED → CANCELLED

All terminal states are immutable.

🏗 Implementation Plan
1️⃣ Create CustodyStateMachine service
class CustodyStateMachine {
canTransition(from: CustodyStatus, to: CustodyStatus): boolean
}
2️⃣ Define transition map
const transitions = {
ACTIVE: ['RETURNED', 'CANCELLED', 'VIOLATION'],
RETURNED: [],
CANCELLED: [],
VIOLATION: []
}
3️⃣ Enforce validation before update
🔒 Acceptance Criteria

Invalid transitions blocked

Terminal states immutable

Timeline events logged

Trust score updated on VIOLATION

Unit tests added

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions