Skip to content

Pet: API

The endpoints, the flow that binds a policy, the lifecycle and the error paths. The entities and fields are in Pet: data model, and the rules that apply on every call are in Conventions.

classDiagram
    class PetCoverage {
        +UUID id
        +string policyNumber
        +DateTime inceptionDate
        +DateTime expiryDate
        +PolicyStatus status
        +int annualReimbursementLimit
        +int waitingPeriod
        +bool preexistingConditions
        +PetBenefit[] benefits
        +create() PetCoverage
        +retrieve(id) PetCoverage
        +renew(id) PetCoverage
    }
    class Pet {
        +UUID id
        +string petName
        +PetKind petKind
        +float age
        +bool purebred
        +PetBreed petBreed
        +float reimbursement
    }
    PetCoverage --> Pet : covers
EndpointScopeWhat it does
POST /petCoverageadminBind a policy against an existing pet
GET /petCoveragedeveloperList, filterable by policyNumber
GET /petCoverage/{id}developerRetrieve one policy
PUT /petCoverage/{id}adminReplace a policy
POST /petCoverage/{id}:endorseadminAmend a policy in force
POST /petCoverage/{id}:canceladminEnd a policy before expiry
POST /petCoverage/{id}:renewadminIssue a new coverage record for a new term
POST /petadminCreate a pet
GET /petdeveloperList pets
GET /pet/{id}developerRetrieve one pet
PUT /pet/{id}adminReplace a pet
sequenceDiagram
    participant Client as Pet Owner App
    participant Gateway as API Gateway
    participant Pet as Pet Service
    Client->>Gateway: POST /pet {petName, petKind, age, breed if dog}
    Gateway->>Pet: createPet
    Pet-->>Gateway: 201 {petId}
    Client->>Gateway: POST /petCoverage {policyholderId, petId, benefits, annualReimbursementLimit, waitingPeriod}
    Gateway->>Pet: createPetCoverage
    Pet->>Pet: validate benefits against petBenefits enum
    Pet->>Pet: Persist with policyStatus=in force
    Pet-->>Gateway: 201 {policyNumber, status: in force}
stateDiagram-v2
    [*] --> InForce : POST /petCoverage
    InForce --> InForce : :endorse (endorsementType applied)
    InForce --> Cancelled : :cancel
    InForce --> Lapsed : non-payment
    InForce --> Extended : :endorse with endorsementType=policy extension
    Extended --> InForce : extension term begins
    Cancelled --> [*]
    Lapsed --> [*]

This diagram is normative. A transition it does not draw is not one an implementation may make.

There is no waiting state, although waitingPeriod is a field on the record. The policy is in force from binding, and the waiting period is calculated against inceptionDate when a claim is evaluated. Trade credit handles its own waiting period the same way.

flowchart TD
    A[POST /petCoverage] --> B{Pet exists?}
    B -->|No| E1[404 - pet not found]
    B -->|Yes| C{petKind in petKind enum?}
    C -->|No| E2[400 - unknown petKind]
    C -->|Yes| D{petKind=dog implies petBreed set?}
    D -->|No| E3[400 - dog breed required]
    D -->|Yes| F{Benefits all in petBenefits enum?}
    F -->|No| E4[400 - unknown benefit]
    F -->|Yes| G[Persist with policyStatus=in force]
    G --> H[201 Created]