# Core concepts

Trips, courses and account configuration determine how an integration behaves. Features marked **Advanced** in the API reference require account configuration; confirm availability with Miare before relying on them.

## Client

A registered user who can use Miare's delivery service.

## Courier

A biker from our pool of bikers who can deliver packages from sources to destinations.
In Miare, bikers don't pick and choose what packages they deliver. Instead, each order is
automatically assigned to one
of the available couriers based on their distance from the source and many other parameters.

## Currency

All monetary amounts in this API are in **Iranian Tomans (IRT)** unless a field explicitly says
otherwise. For example, `price`, `delivery_cost`, package `payment.price`, and boost `amount`
are Tomans.

## Trip

An order given by one of our clients for one or more packages to be delivered. A trip can have one
and only one source
but multiple destinations (and multiple packages to be delivered at those destinations).
Our clients may also indicate that they wish the courier to return to the source at the end of the
trip.

### Trip States

Each trip can be in only one the following states at any given time

| Name | Description |
|---------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| assign_queue | Trip is created but no courier has been assigned to it yet |
| pickup | Trip is assigned to a courier and the courier is on his way to pickup packages from the source |
| dropoff | Trip is picked up by the courier and he is on his way to deliver the packages |
| delivered | All of the packages of the trip are delivered (and if trip was a round trip, courier has returned to the source) |
| canceled_by_miare | Trip is canceled by our support staff. This only happens with source's aggrement or due to a violation of terms of service |
| returning | When the trip is a round trip and it is returning to the source. |
| canceled_by_delay | Trip has been cancelled by Miare due to fulfillment delay from your side |
| canceled_by_client | Trip is canceled by client (either from the web panel or Third Party API) |

## Course

A destination and a package to be delivered at that destination. Each trip can have one or more
courses.
As an example, if a **trip** has two **course**s, our courier will drive to the source, pick up two
packages,
and deliver them to two separate customers in two different destinations.

## Box requirement

Set the optional `requires_box` boolean on each course when creating a trip or adding a course.
It defaults to `false`. When enabled, a course with `requires_box: true` requires a car or a
motorcycle courier with a box. If any course requires a box, the requirement applies to the
courier assigned to the whole trip, including when courses are batched. Courses with different
values can share a trip, provided the courier is compatible. There is no fallback to a motorcycle
courier without a box. Existing client service-level restrictions still apply.

:::caution

Confirm availability with Miare before relying on this feature. While disabled, incoming
`requires_box: true` is accepted but stored as `false`, and course-level box
requirements are not enforced. Enabling the feature later does not restore ignored requirements.
Previously stored values remain visible in responses even while enforcement is disabled.

:::

The value cannot be edited after the course is created. Unrelated updates preserve it.
Trip responses and trip/course webhooks include the stored boolean; older courses without a
stored value are returned as `false`.

## Area

Part of the city defined by a set of latitude-longitudes forming a polygon that Miare operates in
it.
If **source** of a trip is inside an area, that trip is considered part of trips of that specific
area.

## Shift

A period of time in each day defined by a start and an end time. If deadline of a trip is within a
shift, that trip is
considered part of trips of that specific shift.

:::note

The current state of the shifts can be considered constant, and any change will be announced by the sales team.

:::

Start and end time of shifts area as follows:

| name | start | end |
|----------|-------|-------|
| morning | 08:15 | 11:00 |
| noon | 11:00 | 17:30 |
| night | 17:30 | 23:30 |
| midnight | 23:30 | 03:00 |

## Concurrency

The maximum number of **active** trips in each **area** during each **shift** for a client.
If the concurrency limit for a client is reached that is if the total number of its active trips is
equal to its
concurrency limit, the next attempts to create new trips will fail.
Canceling a trip (by client) or ending it will free up a concurrency limit (by moving the trip out
of the active trips
list).

:::note

Only trips in the `assign_queue`, `pickup`, `dropoff`, and `delivered` states are considered active and contribute to the concurrency limit of the client.

:::

## Boosting

Boosting a trip adds the selected price increase and prioritizes it in the assignment queue, increasing
its probability of being offered to and accepted by an available courier. This feature is enabled per
account by Miare's commercial team. If it is not enabled for your account, Boost requests are ignored.

Boost levels and their corresponding amounts are dynamic and set by the commercial team, though changes
are infrequent. Fetch them periodically from the [Boost Levels endpoint](/api/public/delivery#boost-levels).

A boost can be added, changed, or cancelled only while the trip is in the `requested (assign_queue)`
state. Once the trip leaves the assignment queue -it's assigned to a courier- its boost is frozen. A trip with an active boost is
kept out of automatic batching; cancelling the boost removes this batching restriction.

## PoD (Proof of Delivery)

We have implemented a Proof of Delivery (PoD) mechanism to prevent fake deliveries. Depending on your account's
`proof_of_delivery_policy`, the delivery verification code may be managed by Miare or provided by your own system.
This policy is configured for your account by Miare's commercial team. If you want to provide your own delivery
codes, contact our commercial team to enable third-party PoD before sending `delivery_code` in API requests.
For Miare-managed PoD, the system sends a code via SMS to the end customer. Once third-party PoD is enabled, you
provide a 5-digit `delivery_code` for each course when creating the trip or adding the course. At the time of delivery, the
courier must enter this code in the app to confirm the drop-off. Once the code is successfully validated, marking that
delivery as "fake" will no longer be possible.

## Issue

An operational problem that is reported or detected on a trip.

### Issue States

Each issue can be in only one the following states at any given time

| Name | Description |
|----------|--------------------------------------------------------------|
| reported | Issue is created but no staff has picked the issue to follow |
| picked | Issue is picked by a staff and is investigating it |
| resolved | Issue is resolved by one of the user types |

## Batching and identifiers

Persist the client-visible trip `id`, each course `id`, and the current `batch_id`. After automatic batching, the batch can differ from the original trip ID and can change during the trip. Use the current `batch_id` for financial and invoice requests. Auto-batching accounts can create only one course per trip; other enabled accounts can create multi-course trips.

Advanced serialized trip states may also include `receiving`, `departing`, and `batched`, depending on account configuration. Webhook names and current trip states are separate concepts; use the snapshot state and recover with [List Trips](/api/public/delivery#list-trips).
