openapi: 3.1.0
info:
  # Do not change the title, if the title changes, the import paths will be broken
  title: Api
  version: 0.1.0
  description: API specification
servers:
  - url: /api
    description: Base API path
tags:
  - name: health
    description: Health operations
  - name: dashboard
    description: Public dashboard data
  - name: layers
    description: Configurable map layers
  - name: admin
    description: Workspace administration
paths:
  /healthz:
    get:
      operationId: healthCheck
      tags: [health]
      summary: Health check
      description: Returns server health status
      responses:
        "200":
          description: Healthy
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/HealthStatus"
  /dashboard/summary:
    get:
      operationId: getDashboardSummary
      tags: [dashboard]
      summary: Get dashboard indicators and filter options
      parameters:
        - $ref: "#/components/parameters/Governorate"
        - $ref: "#/components/parameters/Status"
        - $ref: "#/components/parameters/Partner"
        - $ref: "#/components/parameters/Source"
        - $ref: "#/components/parameters/Search"
      responses:
        "200":
          description: Dashboard summary
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DashboardSummary"
  /dashboard/activities:
    get:
      operationId: listActivities
      tags: [dashboard]
      summary: List filtered shelter and NFI activities
      parameters:
        - $ref: "#/components/parameters/Governorate"
        - $ref: "#/components/parameters/Status"
        - $ref: "#/components/parameters/Partner"
        - $ref: "#/components/parameters/Source"
        - $ref: "#/components/parameters/Search"
      responses:
        "200":
          description: Activity points
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ShelterActivity"
  /layers:
    get:
      operationId: listLayers
      tags: [layers]
      summary: List configured map layers
      responses:
        "200":
          description: Map layers
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Layer"
    post:
      operationId: createLayer
      tags: [layers]
      summary: Create a map layer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/LayerInput"
      responses:
        "201":
          description: Created layer
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Layer"
  /layers/{layerId}:
    patch:
      operationId: updateLayer
      tags: [layers]
      summary: Update a map layer
      parameters:
        - $ref: "#/components/parameters/LayerId"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/LayerUpdate"
      responses:
        "200":
          description: Updated layer
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Layer"
  /admin/audit-log:
    get:
      operationId: listAuditLog
      tags: [admin]
      summary: List recent workspace changes
      responses:
        "200":
          description: Audit entries
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/AuditEvent"
  /admin/users:
    get:
      operationId: listUsers
      tags: [admin]
      summary: List workspace users
      responses:
        "200":
          description: Workspace users
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/WorkspaceUser"
components:
  parameters:
    Governorate:
      name: governorate
      in: query
      schema:
        type: string
    Status:
      name: status
      in: query
      schema:
        type: string
    Partner:
      name: partner
      in: query
      schema:
        type: string
    Source:
      name: source
      in: query
      schema:
        type: string
    Search:
      name: search
      in: query
      schema:
        type: string
    LayerId:
      name: layerId
      in: path
      required: true
      schema:
        type: number
  schemas:
    HealthStatus:
      type: object
      properties:
        status:
          type: string
      required:
        - status
    DashboardSummary:
      type: object
      required:
        - totalActivities
        - householdsReached
        - peopleReached
        - activePartners
        - lastUpdated
        - governorates
        - statuses
        - partners
        - sources
        - activityTrend
      properties:
        totalActivities:
          type: number
        householdsReached:
          type: number
        peopleReached:
          type: number
        activePartners:
          type: number
        lastUpdated:
          type: string
        governorates:
          type: array
          items:
            type: string
        statuses:
          type: array
          items:
            type: string
        partners:
          type: array
          items:
            type: string
        sources:
          type: array
          items:
            type: string
        activityTrend:
          type: array
          items:
            $ref: "#/components/schemas/TrendPoint"
    TrendPoint:
      type: object
      required: [month, activities, households]
      properties:
        month:
          type: string
        activities:
          type: number
        households:
          type: number
    ShelterActivity:
      type: object
      required:
        - id
        - title
        - partner
        - governorate
        - district
        - status
        - source
        - activityType
        - latitude
        - longitude
        - households
        - people
        - updatedAt
      properties:
        id:
          type: number
        title:
          type: string
        partner:
          type: string
        governorate:
          type: string
        district:
          type: string
        status:
          type: string
        source:
          type: string
        activityType:
          type: string
        latitude:
          type: number
        longitude:
          type: number
        households:
          type: number
        people:
          type: number
        updatedAt:
          type: string
        details:
          type: array
          items:
            $ref: "#/components/schemas/Attribute"
    Attribute:
      type: object
      required: [label, value]
      properties:
        label:
          type: string
        value:
          type: string
    Layer:
      type: object
      required: [id, name, description, sourceType, visibility, priority, featureCount, updatedAt, color, geometryType]
      properties:
        id:
          type: number
        name:
          type: string
        description:
          type: string
        sourceType:
          type: string
        visibility:
          type: boolean
        priority:
          type: number
        featureCount:
          type: number
        updatedAt:
          type: string
        color:
          type: string
        geometryType:
          type: string
        syncStatus:
          type: string
    LayerInput:
      type: object
      required: [name, description, sourceType, geometryType]
      properties:
        name:
          type: string
        description:
          type: string
        sourceType:
          type: string
        geometryType:
          type: string
        color:
          type: string
    LayerUpdate:
      type: object
      properties:
        name:
          type: string
        description:
          type: string
        visibility:
          type: boolean
        priority:
          type: number
        color:
          type: string
    AuditEvent:
      type: object
      required: [id, action, subject, actor, timestamp]
      properties:
        id:
          type: number
        action:
          type: string
        subject:
          type: string
        actor:
          type: string
        timestamp:
          type: string
    WorkspaceUser:
      type: object
      required: [id, name, email, role, status, lastLogin]
      properties:
        id:
          type: number
        name:
          type: string
        email:
          type: string
        role:
          type: string
        status:
          type: string
        lastLogin:
          type: string

