{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hesapla.narch.tech/arac/zam-hesaplama/zam-hesaplama-output.schema.json",
  "title": "Zam hesaplama yanıtı",
  "oneOf": [
    { "$ref": "#/$defs/zamliBulOutput" },
    { "$ref": "#/$defs/oranBulOutput" },
    { "$ref": "#/$defs/zamsizBulOutput" },
    { "$ref": "#/$defs/ardisikListeOutput" },
    { "$ref": "#/$defs/esitOranOutput" },
    { "$ref": "#/$defs/reelOutput" },
    { "$ref": "#/$defs/errorOutput" }
  ],
  "$defs": {
    "moneyAmount": {
      "type": "number",
      "unit": "TL veya birimsiz"
    },
    "cents": {
      "type": "integer",
      "minimum": -9007199254740991,
      "maximum": 9007199254740991,
      "unit": "kuruş veya 1/100 birim"
    },
    "percentage": {
      "type": "number",
      "unit": "%"
    },
    "nullablePercentage": {
      "type": ["number", "null"],
      "unit": "%"
    },
    "factor": {
      "type": "number",
      "unit": "çarpan"
    },
    "nullableFactor": {
      "type": ["number", "null"],
      "unit": "çarpan"
    },
    "rounding": {
      "type": "string",
      "enum": ["kurus", "tam_tl"],
      "unit": null
    },
    "operationType": {
      "type": "string",
      "enum": ["zam", "indirim", "degisim_yok"],
      "unit": null
    },
    "moneyResultBase": {
      "type": "object",
      "required": [
        "basarili", "mod", "yuvarlama", "eski_tutar", "eski_tutar_kurus",
        "yeni_tutar", "yeni_tutar_kurus", "degisim_tutari", "degisim_tutari_kurus"
      ],
      "properties": {
        "basarili": { "const": true, "unit": null },
        "mod": {
          "type": "string",
          "enum": ["zamli_bul", "oran_bul", "zamsiz_bul", "ardisik"],
          "unit": null
        },
        "yuvarlama": { "$ref": "#/$defs/rounding" },
        "eski_tutar": { "$ref": "#/$defs/moneyAmount" },
        "eski_tutar_kurus": { "$ref": "#/$defs/cents" },
        "yeni_tutar": { "$ref": "#/$defs/moneyAmount" },
        "yeni_tutar_kurus": { "$ref": "#/$defs/cents" },
        "degisim_tutari": { "$ref": "#/$defs/moneyAmount" },
        "degisim_tutari_kurus": { "$ref": "#/$defs/cents" }
      }
    },
    "zamliBulOutput": {
      "type": "object",
      "unevaluatedProperties": false,
      "allOf": [
        { "$ref": "#/$defs/moneyResultBase" },
        {
          "required": ["oran", "islem_turu"],
          "properties": {
            "mod": { "const": "zamli_bul" },
            "oran": { "$ref": "#/$defs/percentage" },
            "islem_turu": { "$ref": "#/$defs/operationType" }
          }
        }
      ]
    },
    "oranBulOutput": {
      "type": "object",
      "unevaluatedProperties": false,
      "allOf": [
        { "$ref": "#/$defs/moneyResultBase" },
        {
          "required": ["oran", "islem_turu"],
          "properties": {
            "mod": { "const": "oran_bul" },
            "oran": { "$ref": "#/$defs/percentage" },
            "islem_turu": { "$ref": "#/$defs/operationType" }
          }
        }
      ]
    },
    "zamsizBulOutput": {
      "type": "object",
      "unevaluatedProperties": false,
      "allOf": [
        { "$ref": "#/$defs/moneyResultBase" },
        {
          "required": ["oran", "toplam_carpan", "islem_turu"],
          "properties": {
            "mod": { "const": "zamsiz_bul" },
            "oran": { "$ref": "#/$defs/percentage" },
            "toplam_carpan": { "$ref": "#/$defs/factor" },
            "islem_turu": { "$ref": "#/$defs/operationType" }
          }
        }
      ]
    },
    "stepOutput": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sira", "oran", "onceki_tutar", "onceki_tutar_kurus", "degisim_tutari",
        "degisim_tutari_kurus", "sonraki_tutar", "sonraki_tutar_kurus"
      ],
      "properties": {
        "sira": { "type": "integer", "minimum": 1, "unit": "sıra" },
        "oran": { "$ref": "#/$defs/percentage" },
        "onceki_tutar": { "$ref": "#/$defs/moneyAmount" },
        "onceki_tutar_kurus": { "$ref": "#/$defs/cents" },
        "degisim_tutari": { "$ref": "#/$defs/moneyAmount" },
        "degisim_tutari_kurus": { "$ref": "#/$defs/cents" },
        "sonraki_tutar": { "$ref": "#/$defs/moneyAmount" },
        "sonraki_tutar_kurus": { "$ref": "#/$defs/cents" }
      }
    },
    "ardisikListeOutput": {
      "type": "object",
      "unevaluatedProperties": false,
      "allOf": [
        { "$ref": "#/$defs/moneyResultBase" },
        {
          "required": [
            "ardisik_islem", "oranlar", "toplam_carpan", "bilesik_oran",
            "teorik_toplam_carpan", "teorik_bilesik_oran", "adimlar"
          ],
          "properties": {
            "mod": { "const": "ardisik" },
            "ardisik_islem": { "const": "liste", "unit": null },
            "oranlar": {
              "type": "array",
              "minItems": 1,
              "items": { "$ref": "#/$defs/percentage" },
              "unit": "%"
            },
            "toplam_carpan": { "$ref": "#/$defs/nullableFactor" },
            "bilesik_oran": { "$ref": "#/$defs/nullablePercentage" },
            "teorik_toplam_carpan": { "$ref": "#/$defs/factor" },
            "teorik_bilesik_oran": { "$ref": "#/$defs/percentage" },
            "adimlar": {
              "type": "array",
              "minItems": 1,
              "items": { "$ref": "#/$defs/stepOutput" }
            }
          }
        }
      ]
    },
    "esitOranOutput": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "basarili", "mod", "yuvarlama", "ardisik_islem", "hedef_toplam_oran",
        "donem_sayisi", "tek_zam_orani", "toplam_carpan"
      ],
      "properties": {
        "basarili": { "const": true, "unit": null },
        "mod": { "const": "ardisik", "unit": null },
        "yuvarlama": { "$ref": "#/$defs/rounding" },
        "ardisik_islem": { "const": "esit_oran_bul", "unit": null },
        "hedef_toplam_oran": { "$ref": "#/$defs/percentage" },
        "donem_sayisi": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991,
          "unit": "adet"
        },
        "tek_zam_orani": { "$ref": "#/$defs/percentage" },
        "toplam_carpan": { "$ref": "#/$defs/factor" }
      }
    },
    "reelOutput": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "basarili", "mod", "yuvarlama", "eski_tutar", "eski_tutar_kurus", "zam_orani",
        "enflasyon_orani", "nominal_yeni_tutar", "nominal_yeni_tutar_kurus", "reel_deger",
        "reel_deger_kurus", "reel_degisim_tutari", "reel_degisim_tutari_kurus", "reel_oran",
        "basit_fark_orani", "yontem_farki_yuzde_puani"
      ],
      "properties": {
        "basarili": { "const": true, "unit": null },
        "mod": { "const": "reel", "unit": null },
        "yuvarlama": { "$ref": "#/$defs/rounding" },
        "eski_tutar": { "$ref": "#/$defs/moneyAmount" },
        "eski_tutar_kurus": { "$ref": "#/$defs/cents" },
        "zam_orani": { "$ref": "#/$defs/percentage" },
        "enflasyon_orani": { "$ref": "#/$defs/percentage" },
        "nominal_yeni_tutar": { "$ref": "#/$defs/moneyAmount" },
        "nominal_yeni_tutar_kurus": { "$ref": "#/$defs/cents" },
        "reel_deger": { "$ref": "#/$defs/moneyAmount" },
        "reel_deger_kurus": { "$ref": "#/$defs/cents" },
        "reel_degisim_tutari": { "$ref": "#/$defs/moneyAmount" },
        "reel_degisim_tutari_kurus": { "$ref": "#/$defs/cents" },
        "reel_oran": { "$ref": "#/$defs/percentage" },
        "basit_fark_orani": { "$ref": "#/$defs/percentage" },
        "yontem_farki_yuzde_puani": {
          "type": "number",
          "unit": "yüzde puanı"
        }
      }
    },
    "errorOutput": {
      "type": "object",
      "additionalProperties": false,
      "required": ["basarili", "hata"],
      "properties": {
        "basarili": { "const": false, "unit": null },
        "hata": {
          "type": "object",
          "additionalProperties": false,
          "required": ["kod", "mesaj", "alan"],
          "properties": {
            "kod": { "type": "string", "minLength": 1, "unit": null },
            "mesaj": { "type": "string", "minLength": 1, "unit": null },
            "alan": { "type": ["string", "null"], "unit": null }
          }
        }
      }
    }
  }
}
