{
  "openapi": "3.0.3",
  "info": {
    "title": "SATRIA National Irrigation Interoperability API",
    "version": "22.11.12",
    "description": "Production API read-only untuk integrasi SATRIA dengan Sistem Gubernur Sulawesi Tengah dan sistem pemerintah lainnya. API key dikirim melalui header dan akses dibatasi berdasarkan scope.",
    "contact": {
      "name": "Administrator SATRIA UPT 1 PSDA CIKASDA"
    }
  },
  "servers": [
    {
      "url": "https://upt1cikasda.biz.id/satria/api/v17/national",
      "description": "Production"
    }
  ],
  "security": [
    {
      "ClientId": [],
      "ApiKey": []
    }
  ],
  "tags": [
    {
      "name": "Authentication"
    },
    {
      "name": "Irrigation"
    },
    {
      "name": "IKSI"
    },
    {
      "name": "Areas"
    },
    {
      "name": "Incidents"
    }
  ],
  "components": {
    "securitySchemes": {
      "ClientId": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Client-ID",
        "description": "Identitas API client."
      },
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "API key rahasia. X-Client-Secret tetap didukung untuk kompatibilitas."
      }
    },
    "parameters": {
      "XClientId": {
        "name": "X-Client-ID",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "example": "gov-sulteng-satria-prod"
        }
      },
      "XApiKey": {
        "name": "X-API-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "format": "password"
        }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Client ID atau API key tidak valid, tidak aktif, atau kedaluwarsa.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "ok",
                "message"
              ],
              "properties": {
                "ok": {
                  "type": "boolean",
                  "example": false
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Forbidden": {
        "description": "Scope client tidak mencukupi.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "ok",
                "message"
              ],
              "properties": {
                "ok": {
                  "type": "boolean",
                  "example": false
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "TooManyRequests": {
        "description": "Batas request terlampaui.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "ok",
                "message"
              ],
              "properties": {
                "ok": {
                  "type": "boolean",
                  "example": false
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "InternalError": {
        "description": "Gangguan internal SATRIA.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "ok",
                "message"
              ],
              "properties": {
                "ok": {
                  "type": "boolean",
                  "example": false
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "ResponseMeta": {
        "type": "object",
        "properties": {
          "apiVersion": {
            "type": "string",
            "example": "v17"
          },
          "requestId": {
            "type": "string",
            "format": "uuid"
          },
          "tenant": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "code": {
                "type": "string"
              },
              "level": {
                "type": "string"
              }
            }
          },
          "generatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "PingData": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "ok"
          },
          "service": {
            "type": "string"
          },
          "clientId": {
            "type": "string"
          },
          "clientName": {
            "type": "string"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "MetadataData": {
        "type": "object",
        "properties": {
          "datasetTitle": {
            "type": "string"
          },
          "producer": {
            "type": "object"
          },
          "standard": {
            "type": "string"
          },
          "referenceSystem": {
            "type": "string",
            "example": "EPSG:4326"
          },
          "updateFrequency": {
            "type": "string"
          },
          "dataClassification": {
            "type": "string"
          },
          "contact": {
            "type": "string"
          },
          "license": {
            "type": "string"
          }
        }
      },
      "IrrigationArea": {
        "type": "object",
        "properties": {
          "irrigation_area_id": {
            "type": "string",
            "nullable": true
          },
          "name": {
            "type": "string"
          },
          "asset_count": {
            "type": "integer"
          },
          "service_area_ha": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "Asset": {
        "type": "object",
        "properties": {
          "asset_id": {
            "type": "string"
          },
          "asset_code": {
            "type": "string"
          },
          "irrigation_area_name": {
            "type": "string"
          },
          "asset_name": {
            "type": "string"
          },
          "asset_type": {
            "type": "string"
          },
          "condition": {
            "type": "string"
          },
          "criticality": {
            "type": "string"
          },
          "latitude": {
            "type": "number"
          },
          "longitude": {
            "type": "number"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "IksiComponent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "nullable": true
          },
          "label": {
            "type": "string",
            "nullable": true
          },
          "weight": {
            "type": "number",
            "nullable": true
          },
          "score_pct": {
            "type": "number",
            "nullable": true
          },
          "contribution": {
            "type": "number",
            "nullable": true
          },
          "note": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "IksiAssessment": {
        "type": "object",
        "properties": {
          "assessment_id": {
            "type": "string",
            "nullable": true
          },
          "irrigation_area_id": {
            "type": "string",
            "nullable": true
          },
          "irrigation_area_code": {
            "type": "string",
            "nullable": true
          },
          "irrigation_area_name": {
            "type": "string"
          },
          "assessment_year": {
            "type": "integer",
            "nullable": true
          },
          "assessment_date": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "version": {
            "type": "integer"
          },
          "total_score": {
            "type": "number",
            "nullable": true
          },
          "category": {
            "type": "string",
            "nullable": true
          },
          "verification_status": {
            "type": "string",
            "nullable": true
          },
          "assessor_name": {
            "type": "string",
            "nullable": true
          },
          "components": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/IksiComponent"
            }
          },
          "source_type": {
            "type": "string",
            "nullable": true
          },
          "source_reference": {
            "type": "string",
            "nullable": true
          },
          "notes": {
            "type": "string",
            "nullable": true
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "AreaCategory": {
        "type": "object",
        "properties": {
          "declared_area_ha": {
            "type": "number",
            "nullable": true
          },
          "geometry_area_ha": {
            "type": "number",
            "nullable": true
          },
          "effective_area_ha": {
            "type": "number",
            "nullable": true
          },
          "feature_count": {
            "type": "integer"
          },
          "polygon_available": {
            "type": "boolean"
          },
          "polygon_url": {
            "type": "string",
            "nullable": true
          },
          "source": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "AreaSummary": {
        "type": "object",
        "properties": {
          "irrigation_area_id": {
            "type": "string",
            "nullable": true
          },
          "irrigation_area_code": {
            "type": "string",
            "nullable": true
          },
          "irrigation_area_name": {
            "type": "string"
          },
          "standard_area_ha": {
            "type": "number",
            "nullable": true
          },
          "functional_area_ha": {
            "type": "number",
            "nullable": true
          },
          "potential_area_ha": {
            "type": "number",
            "nullable": true
          },
          "categories": {
            "type": "object",
            "properties": {
              "baku": {
                "$ref": "#/components/schemas/AreaCategory"
              },
              "fungsional": {
                "$ref": "#/components/schemas/AreaCategory"
              },
              "potensial": {
                "$ref": "#/components/schemas/AreaCategory"
              }
            }
          },
          "manifest_version": {
            "type": "string",
            "nullable": true
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "Incident": {
        "type": "object",
        "properties": {
          "incident_id": {
            "type": "string"
          },
          "ticket_number": {
            "type": "string"
          },
          "irrigation_area_name": {
            "type": "string"
          },
          "asset_id": {
            "type": "string",
            "nullable": true
          },
          "incident_type": {
            "type": "string"
          },
          "severity": {
            "type": "string"
          },
          "priority": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "affected_area_ha": {
            "type": "number"
          },
          "latitude": {
            "type": "number"
          },
          "longitude": {
            "type": "number"
          },
          "reported_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "GeoJsonFeatureCollection": {
        "type": "object",
        "required": [
          "type",
          "features"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "FeatureCollection"
            ]
          },
          "metadata": {
            "type": "object"
          },
          "features": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      }
    }
  },
  "paths": {
    "/ping": {
      "get": {
        "summary": "Uji kredensial API",
        "description": "Memvalidasi Client ID, API key, status client, scope, dan masa berlaku.",
        "parameters": [
          {
            "$ref": "#/components/parameters/XClientId"
          },
          {
            "$ref": "#/components/parameters/XApiKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Berhasil",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "example": true
                    },
                    "meta": {
                      "$ref": "#/components/schemas/ResponseMeta"
                    },
                    "data": {
                      "$ref": "#/components/schemas/PingData"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        }
      }
    },
    "/metadata": {
      "get": {
        "summary": "Metadata dataset SATRIA",
        "description": "",
        "parameters": [
          {
            "$ref": "#/components/parameters/XClientId"
          },
          {
            "$ref": "#/components/parameters/XApiKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Berhasil",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "example": true
                    },
                    "meta": {
                      "$ref": "#/components/schemas/ResponseMeta"
                    },
                    "data": {
                      "$ref": "#/components/schemas/MetadataData"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-required-scope": "read:irrigation"
      }
    },
    "/irrigation-areas": {
      "get": {
        "summary": "Daftar Daerah Irigasi",
        "description": "",
        "parameters": [
          {
            "$ref": "#/components/parameters/XClientId"
          },
          {
            "$ref": "#/components/parameters/XApiKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Berhasil",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "example": true
                    },
                    "meta": {
                      "$ref": "#/components/schemas/ResponseMeta"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/IrrigationArea"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-required-scope": "read:irrigation"
      }
    },
    "/assets": {
      "get": {
        "summary": "Inventaris aset dan GeoJSON",
        "description": "",
        "parameters": [
          {
            "$ref": "#/components/parameters/XClientId"
          },
          {
            "$ref": "#/components/parameters/XApiKey"
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "geojson"
              ]
            },
            "description": "Gunakan geojson untuk FeatureCollection titik aset."
          }
        ],
        "responses": {
          "200": {
            "description": "Berhasil",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "ok": {
                          "type": "boolean",
                          "example": true
                        },
                        "meta": {
                          "$ref": "#/components/schemas/ResponseMeta"
                        },
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Asset"
                          }
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/GeoJsonFeatureCollection"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-required-scope": "read:irrigation"
      }
    },
    "/iksi": {
      "get": {
        "summary": "Nilai IKSI terbaru dan histori",
        "description": "",
        "parameters": [
          {
            "$ref": "#/components/parameters/XClientId"
          },
          {
            "$ref": "#/components/parameters/XApiKey"
          },
          {
            "name": "di",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Nama, ID, atau kode D.I."
          },
          {
            "name": "year",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "Tahun penilaian."
          },
          {
            "name": "history",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "True untuk seluruh histori."
          }
        ],
        "responses": {
          "200": {
            "description": "Berhasil",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "example": true
                    },
                    "meta": {
                      "$ref": "#/components/schemas/ResponseMeta"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/IksiAssessment"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-required-scope": "read:iksi"
      }
    },
    "/areas": {
      "get": {
        "summary": "Luas baku, fungsional, potensial, dan polygon",
        "description": "",
        "parameters": [
          {
            "$ref": "#/components/parameters/XClientId"
          },
          {
            "$ref": "#/components/parameters/XApiKey"
          },
          {
            "name": "di",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Nama, ID, atau kode D.I."
          },
          {
            "name": "format",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "geojson"
              ]
            },
            "description": "Gunakan geojson untuk polygon."
          }
        ],
        "responses": {
          "200": {
            "description": "Berhasil",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "ok": {
                          "type": "boolean",
                          "example": true
                        },
                        "meta": {
                          "$ref": "#/components/schemas/ResponseMeta"
                        },
                        "data": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/AreaSummary"
                          }
                        }
                      }
                    },
                    {
                      "$ref": "#/components/schemas/GeoJsonFeatureCollection"
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-required-scope": "read:areas"
      }
    },
    "/incidents": {
      "get": {
        "summary": "Insiden dan laporan aktif",
        "description": "",
        "parameters": [
          {
            "$ref": "#/components/parameters/XClientId"
          },
          {
            "$ref": "#/components/parameters/XApiKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Berhasil",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "example": true
                    },
                    "meta": {
                      "$ref": "#/components/schemas/ResponseMeta"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Incident"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          },
          "500": {
            "$ref": "#/components/responses/InternalError"
          }
        },
        "x-required-scope": "read:incidents"
      }
    }
  }
}