{
  "openapi": "3.0.3",
  "info": {
    "title": "One Dollar Computer Store API",
    "description": "Backend services for One Dollar Computer milestones, allocations, contributions, and administrative operations.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://shop.claudioolmedo.com",
      "description": "Production Store and Admin API Server"
    }
  ],
  "security": [],
  "paths": {
    "/api/campaigns": {
      "get": {
        "summary": "Get Active Milestones",
        "description": "Returns the active computer allocation, prototype, swag, and validation milestones.",
        "responses": {
          "200": {
            "description": "A JSON array of active milestones",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Milestone"
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create or Update Milestone",
        "description": "Adds a new milestone or updates an existing one. Requires Bearer Token authorization.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MilestoneInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully saved milestone",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "campaign": { "$ref": "#/components/schemas/Milestone" }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized access token"
          },
          "500": {
            "description": "Failed to save to database"
          }
        }
      }
    },
    "/api/milestones": {
      "get": {
        "summary": "Get Project Milestones JSON State",
        "description": "Alias endpoint to retrieve active milestones JSON structure.",
        "responses": {
          "200": {
            "description": "A JSON array of active milestones",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Milestone"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/campaigns/delete": {
      "post": {
        "summary": "Delete Milestone",
        "description": "Deletes a milestone by ID. Requires Bearer Token authorization.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["id"],
                "properties": {
                  "id": {
                    "type": "string",
                    "description": "Unique identifier of the milestone to delete."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully deleted milestone",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized access token"
          },
          "500": {
            "description": "Failed to delete from database"
          }
        }
      }
    },
    "/api/contributions": {
      "get": {
        "summary": "Get Public Contributions",
        "description": "Returns the list of public contributor names, amounts, and dates.",
        "responses": {
          "200": {
            "description": "A JSON array of public contributions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "name": { "type": "string", "example": "Anonymous or John Doe" },
                      "amount": { "type": "integer", "description": "Contribution amount in cents" },
                      "date": { "type": "string", "format": "date-time" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/admin/emails": {
      "get": {
        "summary": "Get Contributor Emails",
        "description": "Returns a list of all contributors including names, amounts, dates, and emails. Requires Bearer Token authorization.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of contributors with email addresses",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "email": { "type": "string", "format": "email" },
                      "name": { "type": "string" },
                      "amount": { "type": "integer" },
                      "date": { "type": "string", "format": "date-time" },
                      "allowSocialShare": { "type": "boolean" }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized access token"
          }
        }
      }
    },
    "/api/admin/login": {
      "post": {
        "summary": "Admin Authenticator Login",
        "description": "Authenticates the admin using a 6-digit Google Authenticator code. Returns the Bearer token upon success.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["password"],
                "properties": {
                  "password": {
                    "type": "string",
                    "description": "The current 6-digit dynamic code from the Authenticator app.",
                    "example": "123456"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successfully authenticated",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean", "example": true },
                    "token": {
                      "type": "string",
                      "description": "Bearer token to authorize admin endpoints."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Incorrect Authenticator code"
          }
        }
      }
    },
    "/api/create-checkout-session": {
      "post": {
        "summary": "Create Checkout Session",
        "description": "Initiate a Stripe Checkout session for custom contributions or specific milestone allocations.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckoutRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful session initialization",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": { "type": "string", "format": "uri" },
                    "id": { "type": "string" }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid items or parameters"
          },
          "503": {
            "description": "Stripe is not configured"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "static-token",
        "description": "Pass token received from `/api/admin/login` inside the Authorization header as `Bearer <token>`."
      }
    },
    "schemas": {
      "Milestone": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "type": { "type": "string", "example": "Allocation" },
          "name": { "type": "string", "example": "Fund one computer allocation" },
          "description": { "type": "string" },
          "unitAmount": { "type": "integer", "description": "Target amount in cents" },
          "currency": { "type": "string", "default": "usd" },
          "probability": { "type": "string" },
          "reward": { "type": "string" },
          "imageUrl": { "type": "string" },
          "maxQty": { "type": "integer" },
          "requiresShipping": { "type": "boolean" }
        }
      },
      "MilestoneInput": {
        "type": "object",
        "required": ["id", "type", "name", "description", "unitAmount", "reward"],
        "properties": {
          "id": { "type": "string", "description": "Unique key identifier" },
          "type": { "type": "string", "example": "Allocation" },
          "name": { "type": "string", "example": "Fund one computer allocation" },
          "description": { "type": "string" },
          "unitAmount": { "type": "integer" },
          "currency": { "type": "string", "default": "usd" },
          "probability": { "type": "string" },
          "reward": { "type": "string" },
          "imageUrl": { "type": "string" },
          "maxQty": { "type": "integer", "default": 20 },
          "requiresShipping": { "type": "boolean", "default": false },
          "imageData": {
            "type": "string",
            "description": "Base64 image data string starting with `data:image/` to upload an image file, or `remove` to delete the image."
          }
        }
      },
      "CheckoutRequest": {
        "type": "object",
        "required": ["items"],
        "properties": {
          "email": { "type": "string", "format": "email", "example": "supporter@example.com" },
          "isPublic": { "type": "boolean", "default": true },
          "publicName": { "type": "string" },
          "allowSocialShare": { "type": "boolean", "default": true },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["id", "quantity"],
              "properties": {
                "id": {
                  "type": "string",
                  "description": "Identifier of the milestone, or `custom_contribution` for preset support cards."
                },
                "quantity": { "type": "integer", "minimum": 1 },
                "amount": { "type": "integer", "description": "Used only for custom_contribution to specify dynamic amount in cents." }
              }
            }
          }
        }
      }
    }
  }
}
