{
  "openapi": "3.0.2",
  "info": {
    "version": "3.0.0",
    "title": "Deduplication API",
    "description": "Backend for Epilot Deduplication feature"
  },
  "security": [
    {
      "EpilotAuth": []
    }
  ],
  "paths": {
    "/v1/deduplicate": {
      "post": {
        "operationId": "deduplicate",
        "summary": "deduplicate",
        "description": "Deduplicates Entities",
        "tags": [],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeduplicateRequestBody"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response with Deduplication content",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeduplicateRequestResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/deduplicate/job": {
      "post": {
        "operationId": "deduplicateAsync",
        "summary": "deduplicateAsync",
        "description": "Submits an async deduplication job. Returns a job ID immediately. Poll GET /v1/deduplicate/jobs/{jobId} for status.",
        "tags": [],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DeduplicateRequestBody"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Job accepted. Use the returned jobId to poll for status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeduplicateAsyncResponse"
                }
              }
            }
          }
        }
      }
    },
    "/v1/deduplicate/jobs/{jobId}": {
      "get": {
        "operationId": "getDeduplicationJob",
        "summary": "getDeduplicationJob",
        "description": "Returns the current status of an async deduplication job",
        "tags": [],
        "parameters": [
          {
            "name": "jobId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The job ID returned by POST /v1/deduplicate/job"
          }
        ],
        "responses": {
          "200": {
            "description": "Current job status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DeduplicationJob"
                }
              }
            }
          },
          "404": {
            "description": "Job not found"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "EpilotAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Authorization header with epilot OAuth2 bearer token",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "DeduplicateRequestBody": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "toKeep": {
              "type": "string"
            },
            "toDelete": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "required": [
            "toKeep",
            "toDelete"
          ]
        }
      },
      "DeduplicateRequestResponse": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/Entity"
        }
      },
      "Entity": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string",
            "description": "Entity ID of the Deduplication entry"
          },
          "_org": {
            "type": "string",
            "description": "ID of the Organization that owns this Deduplication"
          },
          "_schema": {
            "type": "string",
            "description": "The Entity schema of this Deduplication"
          },
          "_created_at": {
            "type": "string",
            "description": "The timestamp of when this Deduplication was created",
            "format": "date-time"
          },
          "_updated_at": {
            "type": "string",
            "description": "The timestamp of when this Deduplication was last updated",
            "format": "date-time"
          },
          "_created_by": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              }
            ],
            "description": "The Entity ID of the User that created this Deduplication"
          },
          "created_by": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "number"
              }
            ],
            "description": "The Entity ID of the User that created this Deduplication"
          },
          "_tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Tags associated with this Deduplication"
          },
          "_acl": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "description": "Access Control List for this Deduplication entry"
          },
          "_owners": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "org_id": {
                  "type": "string"
                },
                "user_id": {
                  "type": "string"
                }
              },
              "required": [
                "org_id",
                "user_id"
              ]
            }
          },
          "type": {
            "type": "string",
            "description": "Entity ID of the Deduplication entry"
          }
        },
        "required": [
          "_id"
        ],
        "description": "Base Entity schema"
      },
      "DeduplicateAsyncResponse": {
        "type": "object",
        "properties": {
          "jobId": {
            "type": "string",
            "description": "Job ID to poll for status via GET /v1/deduplicate/jobs/{jobId}"
          },
          "status": {
            "$ref": "#/components/schemas/JobStatus"
          },
          "message": {
            "type": "string",
            "description": "Initial status message"
          }
        },
        "required": [
          "jobId",
          "status",
          "message"
        ],
        "description": "Response returned immediately when a deduplication job is submitted"
      },
      "JobStatus": {
        "type": "string",
        "enum": [
          "pending",
          "processing",
          "completed",
          "failed"
        ]
      },
      "DeduplicationJob": {
        "type": "object",
        "properties": {
          "jobId": {
            "type": "string",
            "description": "Unique identifier for the deduplication job"
          },
          "status": {
            "$ref": "#/components/schemas/JobStatus"
          },
          "message": {
            "type": "string",
            "description": "Human-readable status message (e.g. progress info or error details)"
          },
          "result": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Entity"
            },
            "description": "Array of deduplicated entities, present when status is completed"
          },
          "createdAt": {
            "type": "string",
            "description": "ISO 8601 timestamp of job creation",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "description": "ISO 8601 timestamp of last update",
            "format": "date-time"
          }
        },
        "required": [
          "jobId",
          "status",
          "createdAt",
          "updatedAt"
        ],
        "description": "Represents an async deduplication job"
      }
    }
  },
  "servers": [
    {
      "url": "https://deduplication.sls.epilot.io"
    }
  ]
}
