{
  "openapi": "3.0.3",
  "info": {
    "title": "Tegegn Image Bucket API",
    "version": "1.0.0",
    "description": "High-performance self-hosted image storage and CDN bucket API for uploading, serving, and deleting images."
  },
  "servers": [
    {
      "url": "https://images.tegegn.com.et",
      "description": "Production Server"
    }
  ],
  "paths": {
    "/upload.php": {
      "post": {
        "summary": "Upload an Image",
        "description": "Uploads an image file to the bucket and returns the public CDN URL.",
        "operationId": "uploadImage",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "image": {
                    "type": "string",
                    "format": "binary",
                    "description": "The image file to upload (supports jpg, png, webp, gif, svg, ico)."
                  },
                  "folder": {
                    "type": "string",
                    "description": "Optional subfolder category (e.g. 'avatars', 'products', 'tattoos'). Defaults to current YYYY/MM.",
                    "example": "tattoos"
                  }
                },
                "required": ["image"]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Image uploaded successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "data": {
                      "type": "object",
                      "properties": {
                        "url": { "type": "string", "example": "https://images.tegegn.com.et/uploads/tattoos/1726754000_photo_a1b2c3d4.jpg" },
                        "relative_path": { "type": "string", "example": "uploads/tattoos/1726754000_photo_a1b2c3d4.jpg" },
                        "filename": { "type": "string", "example": "1726754000_photo_a1b2c3d4.jpg" },
                        "original_name": { "type": "string", "example": "photo.jpg" },
                        "size_bytes": { "type": "integer", "example": 142050 },
                        "mime_type": { "type": "string", "example": "image/jpeg" },
                        "extension": { "type": "string", "example": "jpg" },
                        "uploaded_at": { "type": "string", "format": "date-time", "example": "2026-09-19T13:48:00+00:00" }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid file, unsupported extension, or missing parameter",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": false },
                    "error": { "type": "string", "example": "Invalid file extension (.exe). Allowed: jpg, jpeg, png, webp, gif, svg, ico" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/delete.php": {
      "post": {
        "summary": "Delete an Image",
        "description": "Deletes an image from the storage bucket using its relative path or public URL.",
        "operationId": "deleteImage",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "Full public URL or relative path of the file to delete.",
                    "example": "https://images.tegegn.com.et/uploads/tattoos/1726754000_photo_a1b2c3d4.jpg"
                  },
                  "path": {
                    "type": "string",
                    "description": "Relative path of the file.",
                    "example": "uploads/tattoos/1726754000_photo_a1b2c3d4.jpg"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Image deleted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "message": { "type": "string", "example": "File deleted successfully" },
                    "path": { "type": "string", "example": "uploads/tattoos/1726754000_photo_a1b2c3d4.jpg" }
                  }
                }
              }
            }
          },
          "404": {
            "description": "File not found or already deleted",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": false },
                    "error": { "type": "string", "example": "File not found or already deleted" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
