import { FreeTimeBasis, FreeTimeOptions } from "../../types/free-time-options.js";
import "../../types/index.js";
/** A band of chargeable-day ordinals and how many of the charged days fell in it. */
export interface TierBand {
  /** The first chargeable-day ordinal of the band, from 1. */
  from: number;
  /** The last ordinal of the band, or `null` for the open final band. */
  to: number | null;
  /** The number of charged days that fell in the band. */
  days: number;
}
/** What `chargeableDays` returns: the day count an invoice bills, and the dates that back it. */
export interface FreeTimeCharges {
  /** The number of free days the dwell touched, at most the tariff's `freeDays`. */
  freeDaysUsed: number;
  /** The number of counted days on or after `expiresAt` the dwell touched. */
  chargeableDays: number;
  /** The instant free time ended, as a UTC instant, as `freeTimeExpiry` reports it. */
  expiresAt: string;
  /**
   * The local dates charged, ascending. Carriers' day-numbered tariff grids and progressive tiers
   * are applied to this list, and its entries are the dates an itemised invoice can list.
   */
  chargedDates: string[];
  /** The charged days split into the `tiers` bands; one open band when no tiers were given. */
  byTier: TierBand[];
}
/** `FreeTimeOptions` plus how charged days are counted, and the optional tier boundaries. */
export type FreeTimeChargeOptions = FreeTimeOptions & {
  /**
   * How days after expiry are charged: `"calendar"` charges every local day, `"working"` only the
   * working days of `calendar`. No default; see `chargeableDays`.
   */
  chargeBasis: FreeTimeBasis;
  /**
   * The last chargeable-day ordinal of each band, as strictly ascending positive whole numbers:
   * `[5, 10]` is days 1–5, 6–10 and 11 onward. They are day bands, not rates. Every band is
   * returned, an empty one with `days: 0`, and the last is always open.
   *
   * @defaultValue None. `byTier` is the single open band `{ from: 1, to: null }`.
   */
  tiers?: number[];
};
/**
 * Count the days a container is charged for between the start of its clock and its exit,
 * and list the dates behind the count.
 *
 * Lays out free time with the same walk as `freeTimeExpiry`, then counts the days on or after
 * the expiry that the half-open dwell `[clockStart, clockEnd)` touched. The result is the
 * auditable form of a demurrage or detention charge: `chargedDates` lists the days behind the
 * count, which is the list a day-numbered tariff grid is applied to, and the dates an itemised
 * invoice can list. No regulation or industry standard fixes how the days are counted; every term
 * below is the tariff's. GMT computes days, never money: `byTier` says how many days fell in each
 * band so the caller can apply its rates.
 *
 * - **Half-open at the exit.** A day is charged when it started before `clockEnd`, so a
 *   gate-out at exactly `expiresAt` is `0` chargeable days and one nanosecond later is `1`. A
 *   zero-length dwell touches the day it sits on, as `dwellTime` counts. On the calendar basis
 *   with `firstDay: "eventDay"`, `freeDaysUsed + chargeableDays` equals `dwellTime(...).calendarDays`,
 *   with one exception: a fall-back that re-enters the day before the event day (`America/Goose_Bay`,
 *   00:01 on 7 November 2010 back into the 6th) is a date `dwellTime` counts as touched, and a
 *   tariff never counts a date before the event day.
 * - **The free-time terms are `freeTimeExpiry`'s**: `basis`, `timeZone`, `firstDay` and
 *   `calendar` mean the same, and `firstDay` has no default.
 * - **`chargeBasis` says how days after expiry are charged, and has no default.** Many
 *   tariffs count free time and charges alike in calendar days. Where a tariff grants free time in
 *   working days, the days after it are mostly charged as calendar days, weekends and holidays
 *   included (Hapag-Lloyd's tables: "Rate per Calendar day"; ACL: "Once free time expires ...
 *   charged on calendar days"): `basis: "working", chargeBasis: "calendar"`. Some tariffs charge
 *   working days only, for free time and charges alike, so neither counts a day the gate is
 *   closed or a holiday: both `"working"`.
 *   Either `"working"` needs `calendar`. The two differ by every closed day after expiry, so
 *   neither is assumed.
 * - **`freeDays` may be `0`** for a tariff with no free time: `expiresAt` is the start of day one,
 *   the first day counted on `basis` (under `"nextDay"`, the first after the event day), and days
 *   before it are neither free nor charged.
 * - Returns `null` when either instant is invalid, `clockEnd` is before `clockStart` (an
 *   inverted dwell is a data error), `freeDays` is not a whole number of at least `0`, the
 *   options fail as they do for `freeTimeExpiry`, `tiers` has a hole, an unsafe integer or does not ascend, or the walk would pass
 *   10,000 local days.
 * - **Limit at an offset with seconds.** The instant is placed in the offset's whole-minute zone,
 *   moved by its seconds, and the moved instant must be inside Temporal's range. So within the
 *   offset's seconds (under a minute) of the last instant Temporal supports
 *   (`+275760-09-13T00:00:00Z`) for an offset east of UTC, or of the first
 *   (`-271821-04-20T00:00:00Z`) for one west, this returns `null`. An offset to the minute has no
 *   such limit.
 *
 * @param clockStart ISO 8601 instant string of the event that starts the clock
 * @param clockEnd ISO 8601 instant string of the event that stops it (gate-out or empty return)
 * @param freeDays whole number of free days the tariff allows, 0 or more
 * @param options The tariff's counting terms for free time and for charged days, and the tier bands
 * @returns the free days used, the chargeable days, the expiry, the charged dates and the days per tier band, or null on invalid input
 *
 * @example chargeableDays("2024-06-14T19:00:00Z", "2024-06-17T04:00:00Z", 3, { basis: "calendar", chargeBasis: "calendar", timeZone: "America/Port_of_Spain", firstDay: "eventDay" }) // { freeDaysUsed: 3, chargeableDays: 0, expiresAt: "2024-06-17T04:00:00Z", chargedDates: [], byTier: [{ from: 1, to: null, days: 0 }] } (gate-out exactly at expiry is free)
 * @example chargeableDays("2024-06-14T19:00:00Z", "2024-06-17T04:00:01Z", 3, { basis: "calendar", chargeBasis: "calendar", timeZone: "America/Port_of_Spain", firstDay: "eventDay" }) // { freeDaysUsed: 3, chargeableDays: 1, expiresAt: "2024-06-17T04:00:00Z", chargedDates: ["2024-06-17"], byTier: [{ from: 1, to: null, days: 1 }] } (one second later is a charged day)
 * @example chargeableDays("2024-06-14T19:00:00Z", "2024-06-17T04:00:01Z", 3, { basis: "calendar", chargeBasis: "calendar", timeZone: "America/Port_of_Spain", firstDay: "nextDay" }) // { freeDaysUsed: 3, chargeableDays: 0, expiresAt: "2024-06-18T04:00:00Z", chargedDates: [], byTier: [{ from: 1, to: null, days: 0 }] } (the other start-day convention: still free)
 * @example chargeableDays("2024-06-14T19:00:00Z", "2024-06-28T15:00:00Z", 3, { basis: "calendar", chargeBasis: "calendar", timeZone: "America/Port_of_Spain", firstDay: "eventDay", tiers: [5, 10] }) // { freeDaysUsed: 3, chargeableDays: 12, expiresAt: "2024-06-17T04:00:00Z", chargedDates: ["2024-06-17", "2024-06-18", "2024-06-19", "2024-06-20", "2024-06-21", "2024-06-22", "2024-06-23", "2024-06-24", "2024-06-25", "2024-06-26", "2024-06-27", "2024-06-28"], byTier: [{ from: 1, to: 5, days: 5 }, { from: 6, to: 10, days: 5 }, { from: 11, to: null, days: 2 }] }
 * @example chargeableDays("2024-06-14T19:00:00Z", "2024-06-24T15:00:00Z", 3, { basis: "working", chargeBasis: "calendar", timeZone: "America/Port_of_Spain", firstDay: "eventDay", calendar: { weekend: [6, 7], holidays: ["2024-06-19"], timeZone: "America/Port_of_Spain" } }) // { freeDaysUsed: 3, chargeableDays: 6, expiresAt: "2024-06-19T04:00:00Z", chargedDates: ["2024-06-19", "2024-06-20", "2024-06-21", "2024-06-22", "2024-06-23", "2024-06-24"], byTier: [{ from: 1, to: null, days: 6 }] } (free days in working days, every calendar day after expiry charged)
 * @example chargeableDays("2024-06-14T19:00:00Z", "2024-06-24T15:00:00Z", 3, { basis: "working", chargeBasis: "working", timeZone: "America/Port_of_Spain", firstDay: "eventDay", calendar: { weekend: [6, 7], holidays: ["2024-06-19"], timeZone: "America/Port_of_Spain" } }) // { freeDaysUsed: 3, chargeableDays: 3, expiresAt: "2024-06-19T04:00:00Z", chargedDates: ["2024-06-20", "2024-06-21", "2024-06-24"], byTier: [{ from: 1, to: null, days: 3 }] } (working days throughout: closed days after expiry are not charged)
 * @example chargeableDays("2024-06-14T19:00:00Z", "2024-06-15T15:00:00Z", 3, { basis: "calendar", chargeBasis: "calendar", timeZone: "America/Port_of_Spain", firstDay: "eventDay" }) // { freeDaysUsed: 2, chargeableDays: 0, expiresAt: "2024-06-17T04:00:00Z", chargedDates: [], byTier: [{ from: 1, to: null, days: 0 }] } (out on the second free day)
 * @example chargeableDays("2024-06-14T19:00:00Z", "2024-06-16T15:00:00Z", 0, { basis: "calendar", chargeBasis: "calendar", timeZone: "America/Port_of_Spain", firstDay: "eventDay" }) // { freeDaysUsed: 0, chargeableDays: 3, expiresAt: "2024-06-14T04:00:00Z", chargedDates: ["2024-06-14", "2024-06-15", "2024-06-16"], byTier: [{ from: 1, to: null, days: 3 }] } (no free time: every day is charged)
 * @example chargeableDays("2024-06-14T19:00:00Z", "2024-06-28T15:00:00Z", 3, { basis: "calendar", chargeBasis: "calendar", timeZone: "America/Port_of_Spain", firstDay: "eventDay", tiers: [10, 5] }) // null (tiers must ascend)
 * @example chargeableDays("2024-06-17T04:00:01Z", "2024-06-14T19:00:00Z", 3, { basis: "calendar", chargeBasis: "calendar", timeZone: "America/Port_of_Spain", firstDay: "eventDay" }) // null (exit before the clock started)
 * @example chargeableDays("2024-06-14T19:00:00Z", "2024-06-17T04:00:01Z", 3, { basis: "calendar", chargeBasis: "calendar", timeZone: "America/Port_of_Spain" }) // null (firstDay has no default)
 * @example chargeableDays("2024-06-14T19:00:00Z", "2024-06-17T04:00:01Z", 3, { basis: "calendar", timeZone: "America/Port_of_Spain", firstDay: "eventDay" }) // null (chargeBasis has no default)
 */
export declare function chargeableDays(clockStart: string, clockEnd: string, freeDays: number, options: FreeTimeChargeOptions): FreeTimeCharges | null;