{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9-]+\\.[a-z0-9-]+$"
    },
    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$"
    },
    "publisher": {
      "type": "string",
      "minLength": 1,
      "maxLength": 60
    },
    "labelTR": {
      "type": "string",
      "minLength": 1,
      "maxLength": 60
    },
    "descriptionTR": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "runtime": {
      "type": "string",
      "enum": [
        "platform",
        "sandbox",
        "external"
      ]
    },
    "scopes": {
      "maxItems": 10,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 40,
        "pattern": "^[a-z:_-]+$"
      }
    },
    "pii": {
      "type": "object",
      "properties": {
        "buyer": {
          "maxItems": 6,
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "name",
              "email",
              "phone",
              "address",
              "city",
              "ip"
            ]
          }
        },
        "purposeTR": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        }
      },
      "required": [
        "buyer",
        "purposeTR"
      ],
      "additionalProperties": false
    },
    "provider": {
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "payment"
            },
            "methodId": {
              "type": "string",
              "pattern": "^[a-z0-9_]{2,32}$"
            },
            "settlement": {
              "type": "string",
              "enum": [
                "card",
                "cod",
                "transfer"
              ]
            },
            "capabilities": {
              "type": "object",
              "properties": {
                "threeds": {
                  "type": "boolean"
                },
                "hostedForm": {
                  "type": "boolean"
                },
                "installments": {
                  "type": "boolean"
                },
                "refund": {
                  "type": "boolean"
                },
                "partialRefund": {
                  "type": "boolean"
                },
                "binlookup": {
                  "type": "boolean"
                }
              },
              "required": [
                "threeds",
                "hostedForm",
                "installments",
                "refund",
                "partialRefund",
                "binlookup"
              ],
              "additionalProperties": false
            },
            "methodFee": {
              "type": "object",
              "properties": {
                "configKey": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9_]{1,64}$"
                },
                "maxKurus": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 100000
                }
              },
              "required": [
                "configKey",
                "maxKurus"
              ],
              "additionalProperties": false
            },
            "pendingOrder": {
              "type": "object",
              "properties": {
                "expiryConfigKey": {
                  "type": "string",
                  "pattern": "^[a-zA-Z0-9_]{1,64}$"
                },
                "instructions": {
                  "type": "boolean"
                }
              },
              "required": [
                "instructions"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "kind",
            "methodId",
            "settlement",
            "capabilities"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "shipping"
            },
            "methodId": {
              "type": "string",
              "pattern": "^[a-z0-9_]{2,32}$"
            },
            "rates": {
              "type": "object",
              "properties": {
                "timeoutMs": {
                  "default": 1500,
                  "type": "integer",
                  "minimum": 100,
                  "maximum": 3000
                },
                "cacheTtlSeconds": {
                  "default": 0,
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 600
                },
                "onError": {
                  "default": "fail_open",
                  "type": "string",
                  "enum": [
                    "fail_open",
                    "fail_closed"
                  ]
                }
              },
              "additionalProperties": false
            }
          },
          "required": [
            "kind",
            "methodId",
            "rates"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "cargo"
            },
            "methodId": {
              "type": "string",
              "pattern": "^[a-z0-9_]{2,32}$"
            },
            "capabilities": {
              "type": "object",
              "properties": {
                "rateShopping": {
                  "type": "boolean"
                },
                "labelFormats": {
                  "maxItems": 4,
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "PDF",
                      "JPG",
                      "ZPL",
                      "ZPLII"
                    ]
                  }
                },
                "tracking": {
                  "type": "string",
                  "enum": [
                    "webhook",
                    "poll",
                    "both"
                  ]
                },
                "cod": {
                  "type": "boolean"
                },
                "returnLabel": {
                  "type": "boolean"
                },
                "cancel": {
                  "type": "boolean"
                },
                "testMode": {
                  "type": "boolean"
                },
                "senderProfile": {
                  "type": "boolean"
                }
              },
              "required": [
                "rateShopping",
                "labelFormats",
                "tracking",
                "cod",
                "returnLabel",
                "cancel",
                "testMode",
                "senderProfile"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "kind",
            "methodId",
            "capabilities"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "einvoice"
            },
            "docTypes": {
              "minItems": 1,
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "efatura",
                  "earsiv"
                ]
              }
            },
            "testMode": {
              "type": "boolean"
            }
          },
          "required": [
            "kind",
            "docTypes",
            "testMode"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "channel"
            },
            "channelKey": {
              "type": "string",
              "pattern": "^[a-z0-9_]{2,32}$"
            },
            "sync": {
              "type": "object",
              "properties": {
                "orders": {
                  "type": "boolean"
                },
                "stock": {
                  "type": "boolean"
                },
                "price": {
                  "type": "boolean"
                }
              },
              "required": [
                "orders",
                "stock",
                "price"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "kind",
            "channelKey",
            "sync"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "messaging"
            },
            "transports": {
              "minItems": 1,
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "sms",
                  "email"
                ]
              }
            }
          },
          "required": [
            "kind",
            "transports"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "reporting"
            },
            "exports": {
              "maxItems": 2,
              "type": "array",
              "items": {
                "type": "string",
                "enum": [
                  "csv",
                  "xlsx"
                ]
              }
            }
          },
          "required": [
            "kind",
            "exports"
          ],
          "additionalProperties": false
        }
      ]
    },
    "configSchema": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {}
    },
    "secrets": {
      "default": [],
      "maxItems": 8,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "maxLength": 128,
            "pattern": "^[a-z0-9_]+(\\.[a-z0-9_]+)*$"
          },
          "labelTR": {
            "type": "string",
            "minLength": 1,
            "maxLength": 60
          },
          "required": {
            "default": true,
            "type": "boolean"
          },
          "sandboxPrefix": {
            "type": "string",
            "maxLength": 20
          }
        },
        "required": [
          "key",
          "labelTR"
        ],
        "additionalProperties": false
      }
    },
    "webhooks": {
      "default": [],
      "maxItems": 4,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string",
            "pattern": "^[a-z0-9-]{2,24}$"
          },
          "verification": {
            "default": "provider_fetch",
            "type": "string",
            "enum": [
              "provider_fetch",
              "hmac_sha256"
            ]
          },
          "hmacSecretKey": {
            "type": "string",
            "maxLength": 128,
            "pattern": "^[a-z0-9_]+(\\.[a-z0-9_]+)*$"
          },
          "ledger": {
            "type": "string",
            "enum": [
              "payment_events",
              "cargo_events",
              "ext_events"
            ]
          },
          "responseContract": {
            "default": "json_ok",
            "type": "string",
            "enum": [
              "json_ok",
              "literal_ok",
              "empty_200"
            ]
          }
        },
        "required": [
          "token",
          "ledger"
        ],
        "additionalProperties": false
      }
    },
    "jobs": {
      "default": [],
      "maxItems": 3,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z0-9_-]{2,40}$"
          },
          "schedule": {
            "type": "string",
            "enum": [
              "hourly",
              "daily"
            ]
          },
          "timeoutMs": {
            "default": 10000,
            "type": "integer",
            "minimum": 1000,
            "maximum": 30000
          }
        },
        "required": [
          "name",
          "schedule"
        ],
        "additionalProperties": false
      }
    },
    "mail": {
      "default": [],
      "maxItems": 5,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "templateId": {
            "type": "string",
            "pattern": "^[a-z0-9_.-]{2,40}$"
          },
          "trigger": {
            "type": "string",
            "enum": [
              "order.created",
              "order.paid",
              "order.shipped",
              "payment.instructions"
            ]
          },
          "slot": {
            "type": "string",
            "enum": [
              "payment_instructions",
              "order_footer",
              "standalone"
            ]
          },
          "promoFree": {
            "type": "boolean",
            "const": true
          }
        },
        "required": [
          "templateId",
          "trigger",
          "slot",
          "promoFree"
        ],
        "additionalProperties": false
      }
    },
    "events": {
      "default": [],
      "maxItems": 5,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "on": {
            "type": "string",
            "enum": [
              "order.created",
              "order.paid",
              "order.shipped",
              "order.delivered",
              "order.refunded"
            ]
          },
          "handler": {
            "type": "string",
            "pattern": "^[a-z0-9_-]{2,40}$"
          }
        },
        "required": [
          "on",
          "handler"
        ],
        "additionalProperties": false
      }
    },
    "ui": {
      "type": "object",
      "properties": {
        "settingsForm": {
          "type": "object",
          "properties": {
            "fieldLabelsTR": {
              "type": "object",
              "propertyNames": {
                "type": "string",
                "maxLength": 80,
                "pattern": "^\\/[a-zA-Z0-9_/]+$"
              },
              "additionalProperties": {
                "type": "string",
                "maxLength": 80
              }
            },
            "fieldHintsTR": {
              "type": "object",
              "propertyNames": {
                "type": "string",
                "maxLength": 80,
                "pattern": "^\\/[a-zA-Z0-9_/]+$"
              },
              "additionalProperties": {
                "type": "string",
                "maxLength": 200
              }
            },
            "widgetHints": {
              "type": "object",
              "propertyNames": {
                "type": "string",
                "maxLength": 80,
                "pattern": "^\\/[a-zA-Z0-9_/]+$"
              },
              "additionalProperties": {
                "type": "string",
                "enum": [
                  "money",
                  "select",
                  "segmented",
                  "multi-enum",
                  "mode",
                  "rows",
                  "textarea"
                ]
              }
            },
            "hidden": {
              "maxItems": 10,
              "type": "array",
              "items": {
                "type": "string",
                "maxLength": 80,
                "pattern": "^\\/[a-zA-Z0-9_/]+$"
              }
            },
            "order": {
              "maxItems": 20,
              "type": "array",
              "items": {
                "type": "string",
                "maxLength": 80,
                "pattern": "^\\/[a-zA-Z0-9_/]+$"
              }
            },
            "selectOptions": {
              "type": "object",
              "propertyNames": {
                "type": "string",
                "maxLength": 80,
                "pattern": "^\\/[a-zA-Z0-9_/]+$"
              },
              "additionalProperties": {
                "maxItems": 12,
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "value": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "number"
                        }
                      ]
                    },
                    "labelTR": {
                      "type": "string",
                      "maxLength": 60
                    }
                  },
                  "required": [
                    "value",
                    "labelTR"
                  ]
                }
              }
            }
          },
          "required": [
            "fieldLabelsTR"
          ],
          "additionalProperties": false
        },
        "panels": {
          "default": [],
          "maxItems": 4,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "panelId": {
                "type": "string",
                "pattern": "^[a-z0-9-]{2,40}$"
              },
              "zone": {
                "type": "string",
                "enum": [
                  "settings.payments",
                  "settings.cargo",
                  "order.detail.ship",
                  "order.detail.panel",
                  "extension.settings.action",
                  "product.detail.panel",
                  "dashboard.widget",
                  "returns.detail.panel"
                ]
              },
              "titleTR": {
                "type": "string",
                "maxLength": 60
              },
              "when": {
                "type": "object",
                "properties": {
                  "orderStatusIn": {
                    "maxItems": 8,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 32
                    }
                  },
                  "requiresShipping": {
                    "type": "boolean"
                  },
                  "testOnly": {
                    "type": "boolean"
                  }
                },
                "additionalProperties": false
              }
            },
            "required": [
              "panelId",
              "zone"
            ],
            "additionalProperties": false
          }
        },
        "actions": {
          "default": [],
          "maxItems": 3,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "pattern": "^[a-z0-9-]{2,40}$"
              },
              "labelTR": {
                "type": "string",
                "maxLength": 40
              },
              "doneWhen": {
                "type": "object",
                "properties": {
                  "configSet": {
                    "type": "string",
                    "maxLength": 80,
                    "pattern": "^\\/[a-zA-Z0-9_/]+$"
                  }
                },
                "required": [
                  "configSet"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "id",
              "labelTR"
            ],
            "additionalProperties": false
          }
        },
        "pages": {
          "default": [],
          "maxItems": 3,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "slug": {
                "type": "string",
                "pattern": "^[a-z0-9-]{1,32}$"
              },
              "labelTR": {
                "type": "string",
                "maxLength": 40
              }
            },
            "required": [
              "slug",
              "labelTR"
            ],
            "additionalProperties": false
          }
        },
        "themeSections": {
          "default": [],
          "maxItems": 3,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "sectionId": {
                "type": "string",
                "pattern": "^[a-z0-9-]{2,40}$"
              },
              "labelTR": {
                "type": "string",
                "maxLength": 60
              }
            },
            "required": [
              "sectionId",
              "labelTR"
            ],
            "additionalProperties": false
          }
        }
      },
      "additionalProperties": false
    },
    "csp": {
      "type": "object",
      "properties": {
        "scriptSrc": {
          "default": [],
          "maxItems": 4,
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 120,
            "pattern": "^https:\\/\\/[a-z0-9.-]+$"
          }
        },
        "frameSrc": {
          "default": [],
          "maxItems": 4,
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 120,
            "pattern": "^https:\\/\\/[a-z0-9.-]+$"
          }
        },
        "connectSrc": {
          "default": [],
          "maxItems": 4,
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 120,
            "pattern": "^https:\\/\\/[a-z0-9.-]+$"
          }
        },
        "formAction": {
          "default": [],
          "maxItems": 4,
          "type": "array",
          "items": {
            "type": "string",
            "maxLength": 120,
            "pattern": "^https:\\/\\/[a-z0-9.-]+$"
          }
        }
      },
      "additionalProperties": false
    }
  },
  "required": [
    "id",
    "version",
    "publisher",
    "labelTR",
    "descriptionTR",
    "runtime",
    "scopes",
    "configSchema"
  ],
  "additionalProperties": false
}