{
  "post": {
    "tags": ["Image Processing"],
    "summary": "Save color detection SVG",
    "description": "Saves a color detection SVG file to the media directory. The SVG is processed to convert external image URLs to base64-encoded data URIs for security and portability.\n\n**Authentication:**\n- Requires `API-KEY` header with the encryption key (UUID) returned from `/api/save-credentials`\n- The encryption key is used to verify access but does not require specific credential types\n\n**Processing:**\n- Decodes base64-encoded SVG from request body\n- Scans SVG for external image URLs (http/https)\n- Downloads and converts external images to base64 data URIs\n- Saves processed SVG to media directory with unique filename\n\n**File Structure:**\n- SVG files are saved to: `{mediaPath}/{url_dir}/{unique_timestamp}.svg`\n- Filename format: `{timestamp}_{random}.svg`",
    "security": [
      {
        "ApiKeyAuth": []
      }
    ],
    "requestBody": {
      "required": true,
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {
              "canvasSVG": {
                "type": "string",
                "format": "byte",
                "description": "Base64-encoded SVG content. The SVG will be decoded and processed before saving.",
                "example": "PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIi8+PC9zdmc+"
              },
              "url": {
                "type": "string",
                "format": "uri",
                "description": "Reference URL used to determine the save location. Must contain '/media' in the path. The directory structure from this URL will be used for saving the SVG.",
                "example": "https://example.com/media/productdesigner/imagecolor/reference.jpg"
              }
            },
            "required": ["canvasSVG", "url"]
          }
        }
      }
    },
    "responses": {
      "200": {
        "summary": "SVG saved successfully.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string",
                  "example": "Successfully Generated image"
                },
                "data": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": ["Success"],
                      "example": "Success"
                    },
                    "message": {
                      "type": "string",
                      "example": "Successfully Generated image"
                    },
                    "result": {
                      "type": "string",
                      "description": "JSON string containing the saved SVG URL",
                      "example": "{\"data\":\"https://example.com/media/productdesigner/imagecolor/1703520000_123.svg\"}"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "400": {
        "summary": "Bad Request.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string",
                  "examples": ["Please send proper params.", "Invalid base64 SVG data", "Invalid URL format"]
                },
                "data": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": ["Error"],
                      "example": "Error"
                    },
                    "message": {
                      "type": "string",
                      "example": "Please send proper params."
                    },
                    "result": {
                      "type": "string",
                      "example": ""
                    }
                  }
                }
              }
            }
          }
        }
      },
      "401": {
        "summary": "Unauthorized.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string",
                  "examples": [
                    "Encryption key missing. Please provide encryption key in API-KEY header.",
                    "Invalid encryption key format. Expected UUID format.",
                    "Failed to decrypt credentials. Invalid encryption key or corrupted credential file.",
                    "Credential not found. Please ensure credentials are saved and the correct encryption key is provided."
                  ]
                }
              }
            }
          }
        }
      },
      "500": {
        "summary": "Internal Server Error.",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string",
                  "example": "Failed to save SVG"
                },
                "data": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": ["Error"],
                      "example": "Error"
                    },
                    "message": {
                      "type": "string",
                      "example": "Failed to save SVG"
                    },
                    "result": {
                      "type": "string",
                      "example": ""
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
