{
  "$comment": "Machine-readable companion to https://valem.run/calculators/bulgaria/holiday-entitlement. Formula, inputs, outputs, engine-verified test vectors, cited sources and the re-runnable Valem ModelSpec behind the page.",
  "url": "https://valem.run/calculators/bulgaria/holiday-entitlement",
  "dataUrl": "https://valem.run/calculators/bulgaria/holiday-entitlement.json",
  "license": {
    "name": "CC BY 4.0",
    "url": "https://creativecommons.org/licenses/by/4.0/",
    "attribution": "Bulgaria платен годишен отпуск model by Valem (https://valem.run/calculators/bulgaria/holiday-entitlement), CC BY 4.0.",
    "note": "Covers the model — the expression of each rule and the arrangement of the catalog. The rates and thresholds themselves are law and are not licensed by anyone; the cited sources are where they come from."
  },
  "verificationUrl": "https://valem.run/calculators/bulgaria/holiday-entitlement/verify",
  "country": "bulgaria",
  "countryName": "Bulgaria",
  "formula": "holiday-entitlement",
  "formulaName": "Платен годишен отпуск",
  "title": "Платен годишен отпуск 2026 — Bulgaria annual leave (20+ days)",
  "answer": "Under article 155 of the Bulgarian Labour Code the basic paid annual leave is at least 20 working days. Article 156 adds at least 5 working days for work under specific risks and 5 for an irregular working day. A first-time employee can use the leave after 4 months.",
  "lang": "en",
  "currency": "EUR",
  "taxYear": "2026",
  "verification": {
    "claim": "internal-consistency",
    "statement": "The Valem engine reproduces this model's stated formula through 5 self-test cases (below, and re-runnable against the spec). That asserts internal consistency, NOT that the formula matches current law — the cited sources are the evidence for that, and carry the date each was last checked.",
    "selfTestCases": 5,
    "ratesAreIllustrative": false,
    "sourcesCheckedOn": "2026-10-12"
  },
  "sources": [
    {
      "label": "Кодекс на труда, чл. 155–156 — основен и допълнителен платен годишен отпуск (Министерство на труда и социалната политика, консолидиран текст до ДВ бр. 51 от 2026 г.)",
      "url": "https://www.mlsp.government.bg/uploads/24/tpoout/kt.pdf",
      "checked": "2026-10-12"
    }
  ],
  "terminalOutput": "daysRemaining",
  "headlineOutput": "daysEntitled",
  "inputs": [
    {
      "name": "riskConditions",
      "type": "boolean",
      "label": "Work under specific risks to life and health"
    },
    {
      "name": "irregularHours",
      "type": "boolean",
      "label": "Irregular working day (ненормиран работен ден)"
    },
    {
      "name": "daysTaken",
      "type": "number",
      "label": "Working days already taken",
      "minimum": 0
    }
  ],
  "outputs": [
    {
      "name": "daysEntitled",
      "type": "number",
      "formula": "$const.basicWorkingDays + (riskConditions ? $const.riskAdditionalDays : 0) + (irregularHours ? $const.irregularAdditionalDays : 0)"
    },
    {
      "name": "daysRemaining",
      "type": "number",
      "formula": "($r := daysEntitled - $n(daysTaken); $r < 0 ? 0 : $round($r, 1))"
    }
  ],
  "testCases": [
    {
      "description": "BG1 the basic minimum is 20 working days",
      "given": {
        "riskConditions": false,
        "irregularHours": false,
        "daysTaken": 0
      },
      "expect": {
        "daysEntitled": 20
      }
    },
    {
      "description": "BG2 an irregular working day adds 5",
      "given": {
        "riskConditions": false,
        "irregularHours": true,
        "daysTaken": 0
      },
      "expect": {
        "daysEntitled": 25
      }
    },
    {
      "description": "BG3 both supplements: 30",
      "given": {
        "riskConditions": true,
        "irregularHours": true,
        "daysTaken": 0
      },
      "expect": {
        "daysEntitled": 30
      }
    },
    {
      "description": "BG4 days taken come off the remainder",
      "given": {
        "riskConditions": false,
        "irregularHours": false,
        "daysTaken": 8
      },
      "expect": {
        "daysRemaining": 12
      }
    },
    {
      "description": "BG5 never negative",
      "given": {
        "riskConditions": false,
        "irregularHours": false,
        "daysTaken": 40
      },
      "expect": {
        "daysRemaining": 0
      }
    }
  ],
  "spec": {
    "id": "holiday-entitlement-bulgaria",
    "version": "1.0.0",
    "schema": {
      "type": "object",
      "properties": {
        "riskConditions": {
          "type": "boolean"
        },
        "irregularHours": {
          "type": "boolean"
        },
        "daysTaken": {
          "type": "number",
          "minimum": 0
        },
        "daysEntitled": {
          "type": "number",
          "readOnly": true
        },
        "daysRemaining": {
          "type": "number",
          "readOnly": true
        }
      }
    },
    "constants": {
      "basicWorkingDays": 20,
      "riskAdditionalDays": 5,
      "irregularAdditionalDays": 5
    },
    "library": {
      "layers": [
        {
          "id": "statutory",
          "define": "(\n  /* Shared statutory helpers — the canonical copy (docs/sandbox/d8-statutory-families.md §5.4).\n     DO NOT EDIT A SPEC'S INLINED COPY. Edit this file and run `npm run sync:helpers`; a vitest\n     assertion and a Java assertion both require every inlined copy to be byte-identical to this one.\n\n     Why inlined rather than referenced: the `library` section's `ref` form — a library shared\n     between models — is still proposed, gated on the model-references design (see\n     ../../../../docs/design/library/jsonata-library.md). Inlining keeps each spec self-contained,\n     which is what lets `#e=` embedding, `#share=` import and MCP forking work with no resolver.\n\n     TWO TRAPS, both of which fail SILENTLY and both of which bit during the debt-payoff build:\n\n       1. A library function sees ONLY its arguments. It cannot read the consuming document — not\n          through a bare field name, not through `$`, not through `$$`. Everything these helpers\n          need is passed in. (`$const` is late-bound and so would resolve, but relying on it would\n          couple a shared helper to one spec's constant names.)\n       2. ONE null member wrecks a whole aggregate, and the two engines disagree about how. The JS\n          reference implementation THROWS (\"Argument 1 of function sum must be an array of\n          numbers\"); the Java port can instead yield null for the entire aggregate. Neither gives a\n          partial total, and the null-yielding form is the dangerous one because it is silent. So\n          callers coerce with `$n()` below before aggregating, which makes the behaviour identical\n          in both engines — measured, not assumed: see helpers.test.ts.\n\n       3. A PATH STEP DIRECTLY ON A CALL RESULT RETURNS NOTHING in the Java engine. This matters for\n          every caller of $amortize, which is the one helper here returning an object:\n\n              $amortize(p, r, n, 0).months            -> empty in Java, 360 in JS.  WRONG\n              ($a := $amortize(p, r, n, 0); $a.months) -> 360 in both.               RIGHT\n\n          Bind the result to a variable, then step into it. The JS reference accepts both forms, so\n          this is invisible until the page is served by the real engine, and it fails as a blank\n          field rather than an error. Measured with a probe, not inferred — the field simply does\n          not appear. */\n\n  /* Number coercion with an explicit zero default. The guard against trap 2. */\n  $n := function($v) { $v = null or $not($exists($v)) ? 0 : $number($v) };\n\n  /* ISO date -> its year / month / day parts. String slicing rather than $fromMillis formatting:\n     these are statutory dates (\"2026-04-06\"), and a timezone-sensitive round-trip through millis\n     can shift the day, which silently moves a service anniversary across a band boundary. */\n  $isoY := function($d) { $number($substring($d, 0, 4)) };\n  $isoM := function($d) { $number($substring($d, 5, 2)) };\n  $isoD := function($d) { $number($substring($d, 8, 2)) };\n\n  /* Whole years of completed service between two ISO dates. Counts an anniversary as reached only\n     when the month-and-day has arrived, which is what \"completed years of service\" means in every\n     severance statute — not a 365.25-day division, whose drift crosses a 5-year band boundary in\n     the wrong direction roughly one year in four. */\n  $yearsBetween := function($from, $to) { (\n    $y := $isoY($to) - $isoY($from);\n    $beforeAnniversary := $isoM($to) < $isoM($from)\n      or ($isoM($to) = $isoM($from) and $isoD($to) < $isoD($from));\n    $beforeAnniversary ? $y - 1 : $y\n  ) };\n\n  /* Whole completed months between two ISO dates, same convention. */\n  $monthsBetween := function($from, $to) { (\n    $m := ($isoY($to) - $isoY($from)) * 12 + ($isoM($to) - $isoM($from));\n    $isoD($to) < $isoD($from) ? $m - 1 : $m\n  ) };\n\n  /* Inclusive count of days between two ISO dates — both endpoints counted, because a leave year\n     runs from its first day to its last and an employee present on both is present for both.\n     Pro-rata accrual is then $proRataDays(a, b) / $proRataDays(yearStart, yearEnd). */\n  $proRataDays := function($from, $to) {\n    ($toMillis($to) - $toMillis($from)) / 86400000 + 1\n  };\n\n  /* Progressive charge across bands. `$bands` is ordered lowest-first, each {\"upTo\": n, \"rate\": r};\n     the final band's `upTo` is omitted or null to mean \"no ceiling\". Each band's rate applies ONLY\n     to the slice of the amount inside it — the single most common error in a hand-written bracket\n     walk is applying the top rate to the whole amount. Returns 0 for a non-positive amount. */\n  $bandedCharge := function($amount, $bands) { (\n    $a := $n($amount);\n    $a <= 0 ? 0 : $reduce($bands, function($acc, $band) { (\n      $ceiling := $exists($band.upTo) and $band.upTo != null ? $band.upTo : $a;\n      $top := $ceiling < $a ? $ceiling : $a;\n      $slice := $top - $acc.floor;\n      {\n        \"floor\": $top > $acc.floor ? $top : $acc.floor,\n        \"charge\": $acc.charge + ($slice > 0 ? $slice * $n($band.rate) : 0)\n      }\n    ) }, {\"floor\": 0, \"charge\": 0}).charge\n  ) };\n\n  /* Clamp into [floor, cap]. Either bound may be omitted (null) to leave that side open — a benefit\n     with a cap and no floor is as common as one with both. */\n  $clampFloorCap := function($value, $floor, $cap) { (\n    $v := $n($value);\n    $withFloor := $exists($floor) and $floor != null and $v < $floor ? $floor : $v;\n    $exists($cap) and $cap != null and $withFloor > $cap ? $cap : $withFloor\n  ) };\n\n  /* Level annuity payment for a principal over `$months` at `$annualRatePct` nominal, compounded\n     monthly. Falls back to straight-line division at a zero rate, where the standard formula\n     divides by zero. */\n  $annuityPayment := function($principal, $annualRatePct, $months) { (\n    $p := $n($principal);\n    $m := $n($months);\n    $i := $n($annualRatePct) / 1200;\n    $m <= 0 ? 0 : ($i = 0 ? $p / $m : $p * $i * $power(1 + $i, $m) / ($power(1 + $i, $m) - 1))\n  ) };\n\n  /* Amortisation schedule: one row per month until the balance clears or `$months` is reached.\n     Returns {\"payment\", \"months\", \"totalInterest\", \"schedule\": [{month, interest, principal,\n     balance}]}. `$extra` is an optional monthly overpayment.\n\n     A real month-by-month fold rather than a closed form, because an overpayment changes every\n     later row — the same reason debt-payoff simulates. Bounded by `$months`, so it always\n     terminates. */\n  $amortize := function($principal, $annualRatePct, $months, $extra) { (\n    $i := $n($annualRatePct) / 1200;\n    $pay := $annuityPayment($principal, $annualRatePct, $months) + $n($extra);\n    $r := $reduce([1..$n($months)], function($acc, $month) {\n      $acc.balance <= 0 ? $acc : (\n        /* The running balance is kept UNROUNDED and only the emitted row is rounded. Rounding the\n           balance each month instead accumulates drift: at 200,000 over 360 months it left 2.83\n           still owing in the final row, which would break the \"final balance is zero\" invariant\n           (§7.3) and look to a reader like the schedule does not pay the loan off. Lenders compute\n           on the exact balance and adjust the last payment, which is what this does. */\n        $interest := $acc.balance * $i;\n        $due := $acc.balance + $interest < $pay ? $acc.balance + $interest : $pay;\n        $principalPart := $due - $interest;\n        $balance := $acc.balance - $principalPart;\n        {\n          \"balance\": $balance,\n          \"totalInterest\": $acc.totalInterest + $interest,\n          \"schedule\": $append($acc.schedule, [{\n            \"month\": $month,\n            \"interest\": $round($interest, 2),\n            \"principal\": $round($principalPart, 2),\n            \"balance\": $round($balance, 2)\n          }])\n        }\n      )\n    }, {\"balance\": $n($principal), \"totalInterest\": 0, \"schedule\": []});\n    {\n      \"payment\": $round($pay, 2),\n      \"months\": $count($r.schedule),\n      \"totalInterest\": $round($r.totalInterest, 2),\n      \"schedule\": [$r.schedule]\n    }\n  ) };\n\n  [\"n\", \"isoY\", \"isoM\", \"isoD\", \"yearsBetween\", \"monthsBetween\", \"proRataDays\",\n   \"bandedCharge\", \"clampFloorCap\", \"annuityPayment\", \"amortize\"]\n)\n"
        }
      ]
    },
    "defaultValues": [
      {
        "path": "$",
        "expr": "{ 'riskConditions': false, 'irregularHours': false, 'daysTaken': 0 }"
      }
    ],
    "derivations": [
      {
        "path": "$.daysEntitled",
        "expr": "$const.basicWorkingDays + (riskConditions ? $const.riskAdditionalDays : 0) + (irregularHours ? $const.irregularAdditionalDays : 0)"
      },
      {
        "path": "$.daysRemaining",
        "expr": "($r := daysEntitled - $n(daysTaken); $r < 0 ? 0 : $round($r, 1))"
      }
    ],
    "constraints": [],
    "viewDefinition": {
      "renderer": "builtin",
      "defaultView": "main",
      "views": [
        {
          "id": "main",
          "label": "Платен годишен отпуск",
          "layout": "vertical",
          "components": [
            {
              "id": "note",
              "type": "staticText",
              "text": "Кодекс на труда, чл. 155, ал. 4: «Размерът на основния платен годишен отпуск е не по-малко от 20 работни дни.» Art. 156 adds at least 5 working days for work under specific risks to life and health that cannot be removed, and at least 5 for an irregular working day (ненормиран работен ден). Someone starting work for the first time can use the leave after 4 months of service (art. 155, ал. 2)."
            },
            {
              "id": "inputs",
              "type": "fieldSet",
              "label": "Your details",
              "components": [
                {
                  "id": "risk",
                  "type": "checkboxField",
                  "label": "Work under specific risks to life and health",
                  "bind": "$.riskConditions"
                },
                {
                  "id": "irregular",
                  "type": "checkboxField",
                  "label": "Irregular working day (ненормиран работен ден)",
                  "bind": "$.irregularHours"
                },
                {
                  "id": "daysTaken",
                  "type": "numericField",
                  "label": "Working days already taken",
                  "bind": "$.daysTaken"
                }
              ]
            },
            {
              "id": "sep",
              "type": "separatorLine"
            },
            {
              "id": "entitledTile",
              "type": "statTile",
              "label": "Working days entitled",
              "value": "$.daysEntitled"
            },
            {
              "id": "remainingTile",
              "type": "statTile",
              "label": "Working days remaining",
              "value": "$.daysRemaining"
            },
            {
              "id": "assumptions",
              "type": "staticText",
              "text": "Some categories of workers have extended basic leave set by the Council of Ministers (art. 155, ал. 5), and collective or individual agreements may give more; none of that is modelled. Leaving before four months of service brings compensation for unused leave rather than days (art. 155, ал. 3). The code states annual minimums with no proportional rule, so none is applied. Leave pay is not computed here."
            },
            {
              "id": "sources",
              "type": "sourceList",
              "label": "Източници",
              "layers": 1,
              "periodAxis": "flat",
              "items": [
                {
                  "label": "Кодекс на труда, чл. 155–156 — основен и допълнителен платен годишен отпуск (Министерство на труда и социалната политика, консолидиран текст до ДВ бр. 51 от 2026 г.)",
                  "url": "https://www.mlsp.government.bg/uploads/24/tpoout/kt.pdf",
                  "date": "2026-10-12",
                  "covers": [
                    "basicWorkingDays",
                    "riskAdditionalDays",
                    "irregularAdditionalDays"
                  ]
                }
              ]
            }
          ]
        }
      ]
    },
    "tests": [
      {
        "description": "BG1 the basic minimum is 20 working days",
        "given": {
          "$.riskConditions": false,
          "$.irregularHours": false,
          "$.daysTaken": 0
        },
        "expect": {
          "$.daysEntitled": 20
        }
      },
      {
        "description": "BG2 an irregular working day adds 5",
        "given": {
          "$.riskConditions": false,
          "$.irregularHours": true,
          "$.daysTaken": 0
        },
        "expect": {
          "$.daysEntitled": 25
        }
      },
      {
        "description": "BG3 both supplements: 30",
        "given": {
          "$.riskConditions": true,
          "$.irregularHours": true,
          "$.daysTaken": 0
        },
        "expect": {
          "$.daysEntitled": 30
        }
      },
      {
        "description": "BG4 days taken come off the remainder",
        "given": {
          "$.riskConditions": false,
          "$.irregularHours": false,
          "$.daysTaken": 8
        },
        "expect": {
          "$.daysRemaining": 12
        }
      },
      {
        "description": "BG5 never negative",
        "given": {
          "$.riskConditions": false,
          "$.irregularHours": false,
          "$.daysTaken": 40
        },
        "expect": {
          "$.daysRemaining": 0
        }
      }
    ]
  }
}
