# Seller app: discounts the seller pays for

Since 2026-11-04 the seller pays for the discounts on their products (`App\Services\SellerPricing\SellerDiscount`,
ADR `docs/adr/0008-the-seller-pays-for-discounts.md`): the money a running discount takes off one piece of
the customer's price comes off the seller's price too. **A percentage the seller types is of their own
price**: seller price $100, a 10% discount → $10 off their price and $10 off the customer's. The seller is
never shown the customer's price or our commission.

The customer app is unchanged; its `discount` badge ("-20%") now also shows a percentage for discounts set
as an amount, and nothing once a discount ended.

## What the server does with no app change

- Order totals and line prices the seller app already shows are what the seller gets, so they are already
  lower by the discount.
- The panel notifications list (`NotificationCollection`) carries a new seller type
  `product_discount_seller` (`type` = `App\Notifications\ShopProductNotification`, `notification_text`
  ready to show, `data.id` = the first product, `data.product_ids` = all of them, `data.discount` = "12%"
  of the seller's own price, or the amount in their currency). It is written when our staff put a discount
  on the seller's products.
- `GET v2/seller/products/edit/{id}`: `discount` (with `discount_type = percent`) is now a percentage of
  the seller's own price, and the product store/update endpoints read the `discount` they post the same
  way, so an app that shows the field and posts it back needs no change.

## New keys (additive)

| Endpoint | Key | Meaning |
|---|---|---|
| `GET v2/seller/products/all` (`ProductCollection`), per product | `seller_discount` | object below, or `null` when the product has no running or upcoming discount the seller pays for |
| `GET v2/seller/products/edit/{id}` (`ProductDetailsCollection`) | `seller_discount` | same object |
| `GET v2/seller/orders/details/{id}` (`OrderDetailResource`) | `seller_discount`, `seller_discount_label` | the discount taken off the order's total (number in the seller's currency, `0` when none) and its text (`"−$24.00"`, `""` when none) |
| same, each of `order_items` (`OrderItemResource`) | `seller_discount`, `seller_discount_label` | the same for the line; `price` is already after it |

`seller_discount` object of a product (amounts are numbers in the product's `currency_code`):

```json
{
  "state": "running",            // or "upcoming"
  "percent": 10,                 // of the seller's own price
  "cut": 10,                     // taken off one piece of the seller's price
  "seller_price": 100,           // the seller's price of one piece
  "seller_price_after": 90,      // their price while it runs
  "below_zero": false,           // true: the discount is bigger than their price
  "starts_at": null,             // "Y-m-d H:i" or null
  "ends_at": "2026-11-30 23:59", // "Y-m-d H:i" or null
  "discount_label": "الخصم على سعرك 10%: −$10.00 للقطعة ← $90.00"
}
```

## Kapitano's part (2026-11-10, additive)

Since 2026-11-10 a product's discount has two parts (ADR 0012): the seller's and Kapitano's, each with its
own dates; while both run the customer gets the sum. The seller app keeps reading and writing **the seller's
part** through the same fields as before (`discount`, `discount_type`, `date_range` on save; `discount`,
`discount_type`, `discount_start_date`, `discount_end_date` on `products/edit/{id}`), so old versions keep
working: they never see or touch Kapitano's part. `seller_discount` above is the seller's part only.

| Endpoint | Key | Meaning |
|---|---|---|
| `GET v2/seller/products/all`, per product | `kapitano_discount` | object below, or `null` when Kapitano has no running or upcoming part |
| `GET v2/seller/products/edit/{id}` | `kapitano_discount` | same object |

```json
{
  "state": "running",              // or "upcoming"
  "percent": 5,                    // of the customer's price - never an amount of money
  "starts_at": "2026-11-10 00:00", // "Y-m-d H:i" or null
  "ends_at": "2026-11-12 23:59",
  "customer_percent": 13,          // the customer's whole percentage while both parts run, else null
  "label": "تضيف كابيتانو خصماً 5% للزبائن على حسابها · من … إلى …"
}
```

Read only: show `label` under the seller's own discount (a light blue note). An order line's
`seller_discount` is still what the seller bore; Kapitano's part never changes what the seller gets.

## What the app should do

1. On the product list and the product page, show `seller_discount.discount_label` under the price (grey
   when `state` is `upcoming`), and a warning when `below_zero` is true.
2. On the order page, show `seller_discount_label` under a line's price and under the total when it is not
   empty.
3. On the product form, a percentage is of the seller's own price; show "−X per piece ← Y" from the typed
   price and discount, and warn when the discount is bigger than their price (as the website's form does).
