{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/majr-app/json-schema/majr-app-encode-request-schema.json",
  "title": "EncodeRequest",
  "x-generated": "2026-10-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/encoding-openapi.json#/components/schemas/EncodeRequest",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "jobId",
    "contentType",
    "source"
  ],
  "properties": {
    "jobId": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]{1,255}$",
      "description": "Caller-supplied idempotency key (also the queue job id). Safe as a path segment: no separators or traversal."
    },
    "caller": {
      "type": "string",
      "minLength": 1,
      "description": "Optional provenance / metering slug, e.g. \"majr\". Omit it and the service uses the product your key resolves to (key-only onboarding). If you DO send it under key auth it must equal that product (no length cap — existence in the identity store is the gate)."
    },
    "contentType": {
      "type": "string",
      "minLength": 1,
      "maxLength": 255,
      "enum": [
        "video/mp4",
        "video/mpeg",
        "video/quicktime",
        "video/x-m4v",
        "audio/mp4",
        "audio/mpeg",
        "audio/vnd.wave",
        "audio/wave",
        "audio/x-aiff",
        "audio/x-m4a",
        "audio/x-wav",
        "audio/wav",
        "audio/aac",
        "audio/x-aac",
        "image/jpeg",
        "image/png",
        "image/webp",
        "image/heic",
        "image/heif"
      ],
      "description": "MIME type of the source object; selects the encoder. The enum is generated from the deployed encoder registry — anything else is rejected with 400."
    },
    "source": {
      "$ref": "#/$defs/ObjectRef"
    },
    "destination": {
      "$ref": "#/$defs/Destination",
      "description": "Optional (Onramp v1): omit it to write outputs to managed temporary storage — GET /v1/jobs then returns presigned outputs (see JobState). Supply it to write renditions to your own bucket and retrieve them yourself."
    },
    "outputs": {
      "$ref": "#/$defs/Outputs"
    },
    "callback": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "url"
      ],
      "description": "Optional (Onramp v1): omit for polling-first (poll GET /v1/jobs/{jobId}). When present, completion is POSTed here as a signed webhook.",
      "properties": {
        "url": {
          "type": "string",
          "format": "uri",
          "pattern": "^https?://",
          "description": "http(s) URL that receives the signed completion callback. Must resolve to a public address — private, loopback, link-local, and reserved hosts are refused (400 callback_url_not_allowed); the worker also pins the connection to the vetted address and does not follow redirects."
        }
      }
    },
    "privacy": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "retainSource": {
          "type": "boolean",
          "default": true,
          "description": "false => delete the source object after a successful encode."
        }
      }
    }
  },
  "$defs": {
    "Destination": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "bucket",
        "prefix"
      ],
      "properties": {
        "bucket": {
          "type": "string",
          "minLength": 1
        },
        "prefix": {
          "type": "string",
          "minLength": 1,
          "maxLength": 512,
          "pattern": "^[^/]",
          "not": {
            "pattern": "(^|/)\\.\\.(/|$)"
          },
          "description": "Object-key prefix under which all outputs are written, e.g. an upload id. Must not start with \"/\" or contain a \"..\" segment."
        }
      }
    },
    "ObjectRef": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "bucket",
        "key"
      ],
      "properties": {
        "bucket": {
          "type": "string",
          "minLength": 1
        },
        "key": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "Outputs": {
      "type": "object",
      "additionalProperties": false,
      "description": "Optional per-media-type output settings; defaults match majr.",
      "properties": {
        "video": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "format": {
              "type": "string",
              "const": "hls",
              "default": "hls"
            },
            "renditions": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "string",
                "enum": [
                  "240p",
                  "360p",
                  "480p",
                  "720p",
                  "1080p"
                ]
              },
              "description": "Subset of rendition heights; omit for all."
            },
            "poster": {
              "type": "boolean",
              "default": true
            }
          }
        },
        "audio": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "format": {
              "type": "string",
              "const": "m4a",
              "default": "m4a"
            },
            "bitrate": {
              "type": "string",
              "pattern": "^\\d+(\\.\\d+)?[kKmM]?$",
              "default": "192k"
            }
          }
        },
        "image": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "format": {
              "type": "string",
              "const": "webp",
              "default": "webp"
            },
            "maxWidth": {
              "type": "integer",
              "minimum": 1,
              "maximum": 10000,
              "default": 1080
            }
          }
        }
      }
    }
  }
}