import { BuildCreateCardPolicyTemplateRequestResult } from './buildCreateCardPolicyTemplateRequest'; import { CardPolicyCreateFormValues } from './cardPolicyCreateFormValues'; import { CardPolicyCardSelectionRow, CardPolicyChipFieldValue } from './cardPolicyForm/cardPolicyFormTypes'; /** * Wire-shape input mirrors `CreateCardPolicyTemplateRequest` from * `@zeniai/client-epic-state` (used as the `formDraft` type on the * `cardPolicyDetail` slice). We re-use the local type alias from * `buildCreateCardPolicyTemplateRequest` to keep the inverse symmetric. */ export type CardPolicyTemplateFormDraft = BuildCreateCardPolicyTemplateRequestResult; export interface BuildCardPolicyFormValuesFromRequestArgs { /** All cards available to the tenant. Each row is shown in the table; we * pre-check the rows whose `id` is listed in `draft.applyToCards`. */ cardRows: CardPolicyCardSelectionRow[]; /** All MCC categories available; used to recover the chip `id` and `label` * from a saved `optionalCode`. */ categorySearchOptions: CardPolicyChipFieldValue[]; /** Saved template values (i.e. `cardPolicyDetail.formDraft`). */ draft: CardPolicyTemplateFormDraft; /** All vendors available; used to recover the chip `id` from a saved * merchant name. Vendor catalogs may be empty (matches today's create). */ vendorSearchOptions: CardPolicyChipFieldValue[]; /** * Pre-fill the disabled require-receipt row's `amount` with this value * (sourced from `chargeCardConfigState.receiptRequiredAboveAmount.amount` * on the host screen). When the saved policy already has a positive * threshold the saved value wins; this fallback only kicks in for rows * whose saved value is `0` (toggle off). The transaction row falls back * to `0` regardless. */ defaultRequireReceiptAmount?: number; /** BE-suggested categories for the Allow side. See `suggestedAllowMerchants`. */ suggestedAllowCategories?: { mccCodes: string[]; name: string; }[]; /** * Optional BE-suggested merchants for the Allow side. Any name in this * list that the saved template did NOT already select is appended to * the field's `allowItems` as an unselected `+ name` add-back chip so * the user sees the same suggestions they'd see on a fresh policy. * The Allow / Block sides are kept independent so toggling the radio * always reveals the correct mode's seed. */ suggestedAllowMerchants?: string[]; /** BE-suggested categories for the Block side. */ suggestedBlockCategories?: { mccCodes: string[]; name: string; }[]; /** BE-suggested merchants for the Block side. See `suggestedAllowMerchants`. */ suggestedBlockMerchants?: string[]; } /** * Inverse of `buildCreateCardPolicyTemplateRequest`. Seeds the manual * card-policy form with values pulled from a saved template so the edit page * can render with existing fields pre-populated. * * Mapping rules: * - `mode`/`name`/`description` → straight through. * - Vendor mode is `'allow'` if the saved template has any allowed merchants; * otherwise `'block'` if any blocked merchants; otherwise `'allow'` (empty). * Both `allowItems` and `blockItems` are populated independently: * each side carries its own saved selections (matched against * `vendorSearchOptions`) plus its own BE-suggested unselected `+` * add-back chips. Toggling the radio in the picker swaps between the * two without losing the other side's content. * - Category sides follow the same logic against * `allowedEntity.categoryCodes` / `blockedEntity.categoryCodes`. Each * saved code is matched against `categorySearchOptions[i].optionalCode` * to recover the original chip's id and label; codes that don't match * a known category fall back to a synthetic chip labeled by the code * itself. * - `cardSelections` mirrors `cardRows` with `isChecked` flipped on for cards * whose `id` is in `applyToCards`. * - The two limit rows are rebuilt from `spendLimits.transaction` and * `requiredReceiptThreshold`. Each row is enabled iff the saved value is * non-null — i.e. `0` toggles the row ON with `$0`, `null` keeps the * toggle OFF and the row falls back to the default placeholder amount. */ export declare const buildCardPolicyFormValuesFromRequest: ({ draft, cardRows, categorySearchOptions, vendorSearchOptions, defaultRequireReceiptAmount, suggestedAllowMerchants, suggestedBlockMerchants, suggestedAllowCategories, suggestedBlockCategories, }: BuildCardPolicyFormValuesFromRequestArgs) => CardPolicyCreateFormValues;