Skip to main content

btctax_forms/
map.rs

1//! Committed, per-(form, year) field maps: **logical cell → fully-qualified PDF field name**.
2//!
3//! The maps are DATA (TOML committed next to the bundled PDFs), not code — "adding a year" is a
4//! `forms/<year>/` directory (PDF + maps), never a code change. Keys are the fully-qualified,
5//! bracketed AcroForm names (`topmostSubform[0].Page1[0].Table_Line1_Part1[0].Row1[0].f1_03[0]`).
6//!
7//! Nothing here is trusted blindly: the geometric read-back ([`crate::verify`]) re-derives the
8//! column/row bands from the bundled PDF's own widget `/Rect`s and would flag any mis-labeled cell,
9//! and `map_2025_matches_bundled_pdf_fieldset` asserts every name here exists in the PDF.
10
11use crate::error::FormsError;
12use serde::Deserialize;
13
14/// The two identity cells every IRS form carries at its top: the name line and the SSN.
15///
16/// **Required** on the nine full-return schedule maps (a map without it fails at DESERIALIZATION —
17/// fail-closed at load, and every map is loaded by a test), and `Option` on the two maps shared with
18/// the crypto slice (`ScheduleDMap`, `Form1040Map`), whose 2017/2025 editions have no verified identity
19/// FQNs and no `ReturnInputs` to source an identity from. The full-return fillers refuse on `None`.
20///
21/// The SSN's RENDERING is not fixed here: it is chosen per-cell from the PDF's own `/MaxLen` (11 ⇒
22/// hyphenated, 9 ⇒ bare digits — the schedules and the 1040 genuinely differ). See
23/// [`crate::cells::push_identity`].
24#[derive(Debug, Clone, Deserialize)]
25pub struct IdentityCells {
26    /// "Name(s) shown on return" — or, on Schedule C, "Name of proprietor".
27    pub name: String,
28    /// The SSN cell.
29    pub ssn: String,
30}
31
32/// The TY2025 Form 8949 map (embedded at compile time).
33pub const F8949_MAP_2025: &str = include_str!("../forms/2025/f8949.map.toml");
34/// The TY2025 Schedule D map (embedded at compile time).
35pub const SCHEDULE_D_MAP_2025: &str = include_str!("../forms/2025/schedule_d.map.toml");
36/// The TY2025 Schedule SE map (embedded at compile time).
37pub const SCHEDULE_SE_MAP_2025: &str = include_str!("../forms/2025/schedule_se.map.toml");
38/// The TY2025 Form 8283 map (embedded at compile time).
39pub const F8283_MAP_2025: &str = include_str!("../forms/2025/f8283.map.toml");
40/// The TY2025 Form 1040 map (embedded at compile time).
41pub const F1040_MAP_2025: &str = include_str!("../forms/2025/f1040.map.toml");
42
43/// The TY2024 Form 8949 map (embedded at compile time).
44pub const F8949_MAP_2024: &str = include_str!("../forms/2024/f8949.map.toml");
45/// The TY2024 Schedule D map (embedded at compile time).
46pub const SCHEDULE_D_MAP_2024: &str = include_str!("../forms/2024/schedule_d.map.toml");
47/// The TY2024 Schedule SE map (embedded at compile time).
48pub const SCHEDULE_SE_MAP_2024: &str = include_str!("../forms/2024/schedule_se.map.toml");
49/// The TY2024 Form 8283 map (Rev. 12-2023, embedded at compile time).
50pub const F8283_MAP_2024: &str = include_str!("../forms/2024/f8283.map.toml");
51/// The Form 8275 map (Rev. 10-2024, embedded at compile time). ★ Form 8275 is REVISION-versioned, not
52/// tax-year-versioned: this ONE map + its bundled PDF are aliased to EVERY `SUPPORTED_YEAR` — there is
53/// no `F8275_MAP_2017` / `F8275_MAP_2025` (`Form8275Map::for_year` reuses this same parsed map,
54/// re-stamping only the `year` field).
55pub const F8275_MAP_2024: &str = include_str!("../forms/2024/f8275.map.toml");
56/// The TY2024 Form 1040 map (embedded at compile time).
57pub const F1040_MAP_2024: &str = include_str!("../forms/2024/f1040.map.toml");
58/// The TY2024 Form 8959 (Additional Medicare Tax) map (embedded at compile time).
59pub const F8959_MAP_2024: &str = include_str!("../forms/2024/f8959.map.toml");
60/// The TY2024 Form 8960 (Net Investment Income Tax) map (embedded at compile time).
61pub const F8960_MAP_2024: &str = include_str!("../forms/2024/f8960.map.toml");
62/// The TY2024 Form 8995 (QBI deduction, simplified) map (embedded at compile time).
63pub const F8995_MAP_2024: &str = include_str!("../forms/2024/f8995.map.toml");
64/// The TY2024 Schedule 2 (Additional Taxes) map (embedded at compile time).
65pub const SCHEDULE_2_MAP_2024: &str = include_str!("../forms/2024/f1040s2.map.toml");
66/// The TY2024 Schedule 3 (Additional Credits and Payments) map (embedded at compile time).
67pub const SCHEDULE_3_MAP_2024: &str = include_str!("../forms/2024/f1040s3.map.toml");
68/// The TY2024 Schedule A (Itemized Deductions) map (embedded at compile time).
69pub const SCHEDULE_A_MAP_2024: &str = include_str!("../forms/2024/f1040sa.map.toml");
70/// The TY2024 Schedule 1 (Additional Income and Adjustments) map (embedded at compile time).
71pub const SCHEDULE_1_MAP_2024: &str = include_str!("../forms/2024/f1040s1.map.toml");
72/// The TY2024 Schedule C (Profit or Loss From Business) map (embedded at compile time).
73pub const SCHEDULE_C_MAP_2024: &str = include_str!("../forms/2024/f1040sc.map.toml");
74/// The TY2024 Schedule B (Interest and Ordinary Dividends) map (embedded at compile time).
75pub const SCHEDULE_B_MAP_2024: &str = include_str!("../forms/2024/f1040sb.map.toml");
76
77/// The TY2017 Form 8949 map (embedded at compile time).
78pub const F8949_MAP_2017: &str = include_str!("../forms/2017/f8949.map.toml");
79/// The TY2017 Schedule D map (embedded at compile time).
80pub const SCHEDULE_D_MAP_2017: &str = include_str!("../forms/2017/schedule_d.map.toml");
81/// The TY2017 Schedule SE map (OLD short+long form; btctax fills §B long — embedded at compile time).
82pub const SCHEDULE_SE_MAP_2017: &str = include_str!("../forms/2017/schedule_se.map.toml");
83/// The TY2017 Form 8283 map (Rev. 12-2014, "j Other" — embedded at compile time).
84pub const F8283_MAP_2017: &str = include_str!("../forms/2017/f8283.map.toml");
85/// The TY2017 Form 1040 map (line 13, no DA question — embedded at compile time).
86pub const F1040_MAP_2017: &str = include_str!("../forms/2017/f1040.map.toml");
87
88/// The 4 monetary "amount" columns of a Form 8949 / Schedule D totals row: (d) proceeds, (e) cost,
89/// (g) adjustment, (h) gain. Column (f) — the code column — has no total (a spacer), so it is absent.
90#[derive(Debug, Clone, Deserialize)]
91pub struct AmountCols {
92    /// Column (d) — proceeds.
93    pub proceeds_d: String,
94    /// Column (e) — cost basis.
95    pub cost_e: String,
96    /// Column (g) — adjustment amount.
97    pub adj_g: String,
98    /// Column (h) — gain/loss.
99    pub gain_h: String,
100}
101
102/// One Form 8949 part (Part I short-term on page 0, Part II long-term on page 1).
103#[derive(Debug, Clone, Deserialize)]
104pub struct PartMap {
105    /// `"short"` (Part I) or `"long"` (Part II).
106    pub term: String,
107    /// 0-based page index of this part within the bundled 2-page PDF.
108    pub page: usize,
109    /// The "not reported to the IRS" box checkbox field for this part's revision: the digital-asset
110    /// **Box I** (ST) / **Box L** (LT) on the 2025 map, and the securities **Box C** / **Box F** on
111    /// the pre-2025 (2024/2017) maps. Which one this is depends on the year the map was loaded for.
112    pub box_field: String,
113    /// The checkbox on-state (a PDF name without the leading `/`), e.g. `"6"`.
114    pub box_on: String,
115    /// The line-2 per-part totals row (d,e,g,h).
116    pub totals: AmountCols,
117    /// The 11 data rows; each row is the 8 column field names in order a,b,c,d,e,f,g,h.
118    pub rows: Vec<Vec<String>>,
119}
120
121/// The full Form 8949 field map for one tax year.
122#[derive(Debug, Clone, Deserialize)]
123pub struct Form8949Map {
124    /// `"f8949"`.
125    pub form: String,
126    /// Tax year (e.g. 2025).
127    pub year: i32,
128    /// "Name(s) shown on return" + SSN — on **both pages** (the 8949 is a two-page detail attachment, and
129    /// each page carries the header). `Option`: the crypto slice never writes it, and the 2017/2025 maps
130    /// have no verified FQNs. The FULL-return filler refuses on `None` — an unnamed 8949 is not filable
131    /// (Fable P6 r1 I3).
132    #[serde(default)]
133    pub identity_page1: Option<IdentityCells>,
134    #[serde(default)]
135    pub identity_page2: Option<IdentityCells>,
136    /// Rows per part per page — **map data**, not a hard-coded constant (a new form revision that
137    /// changes the grid is a data-only edit).
138    pub rows_per_page: usize,
139    /// The data-grid subform token used to re-derive the geometry bands — **per-year map config**,
140    /// not a const (2024 = `Table_Line1`, 2025 = `Table_Line1_Part`; the row fqns differ by year).
141    pub table_token: String,
142    /// Part I then Part II.
143    pub parts: Vec<PartMap>,
144}
145
146impl Form8949Map {
147    /// Parse the committed TOML.
148    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
149        toml::from_str(toml_src)
150    }
151
152    /// The TY2025 map.
153    pub fn ty2025() -> Self {
154        Self::parse(F8949_MAP_2025).expect("bundled f8949 2025 map parses")
155    }
156
157    /// The TY2024 map.
158    pub fn ty2024() -> Self {
159        Self::parse(F8949_MAP_2024).expect("bundled f8949 2024 map parses")
160    }
161
162    /// The TY2017 map (pre-1099-DA: Box C/F, `/3`; field-identical grid to 2024).
163    pub fn ty2017() -> Self {
164        Self::parse(F8949_MAP_2017).expect("bundled f8949 2017 map parses")
165    }
166
167    /// The map for a supported tax year.
168    pub fn for_year(year: i32) -> Result<Self, FormsError> {
169        match year {
170            2017 => Ok(Self::ty2017()),
171            2024 => Ok(Self::ty2024()),
172            2025 => Ok(Self::ty2025()),
173            _ => Err(FormsError::UnsupportedYear(year)),
174        }
175    }
176
177    /// The part with the given term, if present.
178    pub fn part(&self, term: &str) -> Option<&PartMap> {
179        self.parts.iter().find(|p| p.term == term)
180    }
181}
182
183/// A checkbox choice (field + on-state) — used for the Schedule D QOF Yes/No answer and the Form 1040
184/// Digital-Asset Yes/No question.
185#[derive(Debug, Clone, Deserialize)]
186pub struct CheckChoice {
187    /// The checkbox field name.
188    pub field: String,
189    /// On-state PDF name (without leading `/`).
190    pub on: String,
191}
192
193/// A dollars-field + cents-field PAIR (the 2017 Schedule SE / Form 1040 / Form 8283 split every money
194/// amount into a whole-dollars field and a 2-digit cents field). The geometric oracle treats the pair
195/// as ONE logical cell **at the dollars-field geometry** (the cents field rides along as an authorized
196/// but geometry-exempt write). Because both fields descend from the same AcroForm root, `merge_copies`
197/// (which renames only the root `/T`) rewrites BOTH names as a unit — so overflow is safe.
198#[derive(Debug, Clone, Deserialize)]
199pub struct MoneyPair {
200    /// The whole-dollars field (the one the geometry oracle checks — column-x + row/descent).
201    pub dollars_field: String,
202    /// The 2-digit cents field (an authorized write; NOT independently geometry-checked).
203    pub cents_field: String,
204}
205
206/// A monetary cell: a single field carrying the whole formatted amount (2024/2025), or a
207/// dollars+cents [`MoneyPair`] (the 2017 forms). Deserializes untagged: a TOML **string** →
208/// [`MoneyCell::Single`]; a TOML **inline table** `{ dollars_field, cents_field }` →
209/// [`MoneyCell::Pair`].
210#[derive(Debug, Clone, Deserialize)]
211#[serde(untagged)]
212pub enum MoneyCell {
213    /// A single field holding the whole formatted amount.
214    Single(String),
215    /// A dollars-field + cents-field pair.
216    Pair(MoneyPair),
217}
218
219impl MoneyCell {
220    /// Every PDF field this cell targets (1 for a single, 2 for a pair) — for coverage guards.
221    pub fn fields(&self) -> Vec<&str> {
222        match self {
223            MoneyCell::Single(f) => vec![f.as_str()],
224            MoneyCell::Pair(p) => vec![p.dollars_field.as_str(), p.cents_field.as_str()],
225        }
226    }
227}
228
229/// A per-year default: the Digital-Asset question is present unless a year's map says otherwise.
230fn default_da_present() -> bool {
231    true
232}
233
234/// The Form 1040 capital-gains field map for one tax year: the capital-gain amount cell (line 7a in
235/// 2025 / line 7 in 2024 / **line 13** in 2017) + the Digital-Asset question (absent in 2017).
236/// The Form 1040's identity block (P6.2) — dumped and correlated against the printed form, never
237/// extrapolated. The SSN cells here declare `/MaxLen 9` (comb), so they take the nine BARE digits,
238/// while every schedule's SSN cell is `/MaxLen 11` and takes the hyphenated form. `push_identity`
239/// reads each cell's capacity rather than assuming either.
240#[derive(Debug, Clone, Deserialize)]
241pub struct Form1040HeaderCells {
242    pub taxpayer_first: String,
243    pub taxpayer_last: String,
244    pub taxpayer_ssn: String,
245    pub spouse_first: String,
246    pub spouse_last: String,
247    pub spouse_ssn: String,
248    pub address_street: String,
249    pub address_apt: String,
250    pub address_city: String,
251    pub address_state: String,
252    pub address_zip: String,
253    /// "If you checked the MFS box, enter the name of your spouse" — written on MFS only.
254    pub mfs_spouse_name: String,
255    /// The signature block's occupation cells (page 2).
256    pub occupation_taxpayer: String,
257    pub occupation_spouse: String,
258    /// The taxpayer's Identity Protection PIN cell (page 2, a 6-character comb). A paper return that
259    /// omits an ISSUED IP PIN is rejected or delayed (ARCH-P6.3a Q7 item 5).
260    pub ip_pin: String,
261    /// The §6096 Presidential Election Campaign boxes.
262    pub presidential_taxpayer: CheckChoice,
263    pub presidential_spouse: CheckChoice,
264    /// "Someone can claim: You / Your spouse as a dependent" — the §63(c)(5) floor's own checkbox.
265    pub claimed_dependent_taxpayer: CheckChoice,
266    pub claimed_dependent_spouse: CheckChoice,
267    /// "Spouse itemizes on a separate return or you were a dual-status alien" — §63(c)(6).
268    pub mfs_spouse_itemizes: CheckChoice,
269    /// ★ The four §63(f) aged/blind boxes. The IRS validates a nonstandard standard deduction by
270    /// COUNTING these, so L12 and this checkbox count must agree or the return fails its own
271    /// arithmetic cross-check (`p6-aged-blind-checkboxes-missing`).
272    pub taxpayer_aged: CheckChoice,
273    pub taxpayer_blind: CheckChoice,
274    pub spouse_aged: CheckChoice,
275    pub spouse_blind: CheckChoice,
276    /// "If more than four dependents, see instructions and check here" — v1 REFUSES instead (the
277    /// continuation statement is a synthetic page generator we do not have; same posture as Schedule
278    /// B's >14-payer refusal, SPEC §7.4 as amended). Mapped so the refusal can name the cell it will
279    /// not fill.
280    pub more_than_four_dependents: CheckChoice,
281    /// The four dependents rows the form physically has.
282    pub dependent_rows: Vec<DependentRowCells>,
283}
284
285/// One row of the 1040's dependents table. The name is a SINGLE cell spanning the printed
286/// "(1) First name / Last name" columns — the form has one widget there, not two.
287#[derive(Debug, Clone, Deserialize)]
288pub struct DependentRowCells {
289    pub name: String,
290    pub ssn: String,
291    pub relationship: String,
292    /// The Child-Tax-Credit box. NEVER checked: v1 omits CTC/ODC entirely (1040 L19 = 0, with the
293    /// `CtcOdcOmitted` advisory), and a checked credit box beside a zero credit is a form
294    /// contradicting itself. Mapped so the no-unmapped oracle knows the cell exists and is DELIBERATELY
295    /// left blank.
296    pub ctc: CheckChoice,
297    /// The Credit-for-Other-Dependents box. Never checked, same reason.
298    pub odc: CheckChoice,
299}
300
301#[derive(Debug, Clone, Deserialize)]
302pub struct Form1040Map {
303    /// `"f1040"`.
304    pub form: String,
305    /// Tax year.
306    pub year: i32,
307    /// The full-return identity BLOCK (P6.2). The 1040's header is not two cells like a schedule's: it
308    /// is names + SSNs + address + the §63(f) aged/blind checkboxes + the dependents table. `Option`
309    /// because this map is SHARED with the crypto slice, whose 2017/2025 editions have no verified
310    /// header FQNs; the FULL-return filler refuses on `None` rather than emit an unnamed 1040.
311    #[serde(default)]
312    pub header: Option<Form1040HeaderCells>,
313    /// The capital-gain amount cell (line 7a for 2025, line 7 for 2024, **line 13 for 2017**). A
314    /// single field on 2024/2025; a dollars+cents [`MoneyPair`] on the 2017 form.
315    pub line7a: MoneyCell,
316    /// Whether this year's 1040 carries the Digital-Asset question — **per-year scaffolding**. When
317    /// `true` (2024/2025) the fill answers it "Yes" and runs the map-independent adjacency guard;
318    /// **2017 sets it `false`** (no DA question — the map omits `da_yes`/`da_no` and the fill produces
319    /// the 1040 iff there is reportable capital activity).
320    #[serde(default = "default_da_present")]
321    pub da_present: bool,
322    /// Digital-Asset question "Yes" (LEFT member of the adjacent pair, on-state `/1`). `None` when the
323    /// year's 1040 has no DA question (2017).
324    #[serde(default)]
325    pub da_yes: Option<CheckChoice>,
326    /// Digital-Asset question "No" (right member, on-state `/2`) — never checked by btctax. `None`
327    /// when the year's 1040 has no DA question (2017).
328    #[serde(default)]
329    pub da_no: Option<CheckChoice>,
330
331    // ── Full-return extension (P6). Absent from the 2017/2025 maps, hence optional. ───────────
332    /// L1a — Σ W-2 box 1. AMOUNT column. Full-return only.
333    #[serde(default)]
334    pub line1a: Option<MoneyCell>,
335    /// L2a — tax-exempt interest. SUBLINE column. Full-return only (absent from the 2017/2025 maps).
336    #[serde(default)]
337    pub line2a: Option<MoneyCell>,
338    /// L1z — wages. AMOUNT column.
339    #[serde(default)]
340    pub line1z: Option<MoneyCell>,
341    /// L2b — taxable interest. AMOUNT column.
342    #[serde(default)]
343    pub line2b: Option<MoneyCell>,
344    /// L3a — qualified dividends. **SUBLINE column** (x ≈ [252,324]), not MID or AMOUNT.
345    #[serde(default)]
346    pub line3a: Option<MoneyCell>,
347    /// L3b — ordinary dividends. AMOUNT column.
348    #[serde(default)]
349    pub line3b: Option<MoneyCell>,
350    /// L8 — Schedule 1's printed L10.
351    #[serde(default)]
352    pub line8: Option<MoneyCell>,
353    /// L9 — total income.
354    #[serde(default)]
355    pub line9: Option<MoneyCell>,
356    /// L10 — Schedule 1's printed L26.
357    #[serde(default)]
358    pub line10: Option<MoneyCell>,
359    /// L11 — AGI.
360    #[serde(default)]
361    pub line11: Option<MoneyCell>,
362    /// L12 — the deduction claimed. **★ `f1_57` on the 2024 form is L12; on the 2025 form the same
363    /// field name is L1z** (SPEC §7.4). Per-(form, year) maps exist for exactly this.
364    #[serde(default)]
365    pub line12: Option<MoneyCell>,
366    /// L13 — Form 8995's printed L15 (QBI).
367    #[serde(default)]
368    pub line13: Option<MoneyCell>,
369    /// L14 — 12 + 13.
370    #[serde(default)]
371    pub line14: Option<MoneyCell>,
372    /// L15 — taxable income.
373    #[serde(default)]
374    pub line15: Option<MoneyCell>,
375    /// L16 — tax.
376    #[serde(default)]
377    pub line16: Option<MoneyCell>,
378    /// L17 — Schedule 2's printed L3 (always 0 in v1).
379    #[serde(default)]
380    pub line17: Option<MoneyCell>,
381    /// L18 — 16 + 17.
382    #[serde(default)]
383    pub line18: Option<MoneyCell>,
384    /// L19 — CTC/ODC (always 0 — a §3.4 conservative omission).
385    #[serde(default)]
386    pub line19: Option<MoneyCell>,
387    /// L20 — Schedule 3's printed L8.
388    #[serde(default)]
389    pub line20: Option<MoneyCell>,
390    /// L21 — 19 + 20.
391    #[serde(default)]
392    pub line21: Option<MoneyCell>,
393    /// L22 — 18 − 21.
394    #[serde(default)]
395    pub line22: Option<MoneyCell>,
396    /// L23 — Schedule 2's printed L21.
397    #[serde(default)]
398    pub line23: Option<MoneyCell>,
399    /// L24 — TOTAL TAX.
400    #[serde(default)]
401    pub line24: Option<MoneyCell>,
402    /// L25a — W-2 withholding. MID column.
403    #[serde(default)]
404    pub line25a: Option<MoneyCell>,
405    /// L25b — 1099 withholding. MID column.
406    #[serde(default)]
407    pub line25b: Option<MoneyCell>,
408    /// L25c — other withholding (Form 8959's printed L24). MID column.
409    #[serde(default)]
410    pub line25c: Option<MoneyCell>,
411    /// L25d — 25a + 25b + 25c.
412    #[serde(default)]
413    pub line25d: Option<MoneyCell>,
414    /// L26 — estimated tax payments.
415    #[serde(default)]
416    pub line26: Option<MoneyCell>,
417    /// L31 — Schedule 3's printed L15. MID column.
418    #[serde(default)]
419    pub line31: Option<MoneyCell>,
420    /// L32 — total other payments.
421    #[serde(default)]
422    pub line32: Option<MoneyCell>,
423    /// L33 — TOTAL PAYMENTS.
424    #[serde(default)]
425    pub line33: Option<MoneyCell>,
426    /// L34 — overpayment.
427    #[serde(default)]
428    pub line34: Option<MoneyCell>,
429    /// L35a — refunded to you.
430    #[serde(default)]
431    pub line35a: Option<MoneyCell>,
432    /// L37 — amount you owe.
433    #[serde(default)]
434    pub line37: Option<MoneyCell>,
435    /// The 5-way filing-status checkbox group.
436    #[serde(default)]
437    pub filing_status: Option<FilingStatusBoxes>,
438}
439
440/// The 1040's **5-way filing-status checkbox group**.
441///
442/// **★ The leaf field names COLLIDE.** Two distinct fields are both called `c1_3[0]` and two are both
443/// called `c1_3[1]`, distinguished only by their parent subform:
444///
445/// | status | fully-qualified name | on-state |
446/// |---|---|---|
447/// | Single | `…FilingStatus_ReadOrder[0].c1_3[0]` | `1` |
448/// | HoH | `…Page1[0].c1_3[0]` (no wrapper!) | `2` |
449/// | MFJ | `…FilingStatus_ReadOrder[0].c1_3[1]` | `3` |
450/// | MFS | `…FilingStatus_ReadOrder[0].c1_3[2]` | `4` |
451/// | QSS | `…Page1[0].c1_3[1]` (no wrapper!) | `5` |
452///
453/// A map keyed on the leaf name would silently check the WRONG FILING STATUS — which changes the
454/// standard deduction, every bracket, and every threshold on the return. The on-states are distinct
455/// and independently corroborate the mapping, so the filler asserts both.
456#[derive(Debug, Clone, Deserialize)]
457pub struct FilingStatusBoxes {
458    /// Single — on-state `1`.
459    pub single: CheckChoice,
460    /// Head of household — on-state `2`.
461    pub hoh: CheckChoice,
462    /// Married filing jointly — on-state `3`.
463    pub mfj: CheckChoice,
464    /// Married filing separately — on-state `4`.
465    pub mfs: CheckChoice,
466    /// Qualifying surviving spouse — on-state `5`.
467    pub qss: CheckChoice,
468}
469
470impl Form1040Map {
471    /// Parse the committed TOML.
472    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
473        toml::from_str(toml_src)
474    }
475
476    /// The TY2025 map.
477    pub fn ty2025() -> Self {
478        Self::parse(F1040_MAP_2025).expect("bundled f1040 2025 map parses")
479    }
480
481    /// The TY2024 map.
482    pub fn ty2024() -> Self {
483        Self::parse(F1040_MAP_2024).expect("bundled f1040 2024 map parses")
484    }
485
486    /// The TY2017 map (capital gain on line 13; NO Digital-Asset question).
487    pub fn ty2017() -> Self {
488        Self::parse(F1040_MAP_2017).expect("bundled f1040 2017 map parses")
489    }
490
491    /// The map for a supported tax year.
492    pub fn for_year(year: i32) -> Result<Self, FormsError> {
493        match year {
494            2017 => Ok(Self::ty2017()),
495            2024 => Ok(Self::ty2024()),
496            2025 => Ok(Self::ty2025()),
497            _ => Err(FormsError::UnsupportedYear(year)),
498        }
499    }
500}
501
502/// One Form 8283 **Section A** row (Donated Property of $5,000 or Less): the 8 filled columns.
503#[derive(Debug, Clone, Deserialize)]
504pub struct Section8283ARow {
505    /// (a) Name and address of the donee organization.
506    pub donee: String,
507    /// (c) Description and condition of donated property.
508    pub desc: String,
509    /// (d) Date of the contribution (full date).
510    pub date_contrib: String,
511    /// (e) Date acquired by donor (mo., yr.).
512    pub date_acq: String,
513    /// (f) How acquired by donor.
514    pub how: String,
515    /// (g) Donor's cost or adjusted basis (money — a [`MoneyPair`] on the 2017 Rev. 12-2014 form).
516    pub cost: MoneyCell,
517    /// (h) Fair market value (money — a [`MoneyPair`] on the 2017 form).
518    pub fmv: MoneyCell,
519    /// (i) Method used to determine the FMV.
520    pub method: String,
521}
522
523/// Form 8283 Section A (page 1, Line 1) — up to 4 rows A–D.
524#[derive(Debug, Clone, Deserialize)]
525pub struct Section8283A {
526    /// The 4 rows A–D.
527    pub rows: Vec<Section8283ARow>,
528}
529
530/// One Form 8283 **Section B Part I** row (Over $5,000): the filled columns.
531#[derive(Debug, Clone, Deserialize)]
532pub struct Section8283BRow {
533    /// (a) Description of donated property.
534    pub desc: String,
535    /// (c) Appraised fair market value (money — a [`MoneyPair`] on the 2017 Rev. 12-2014 form).
536    pub fmv: MoneyCell,
537    /// (d) Date acquired by donor (mo., yr.).
538    pub date_acq: String,
539    /// (e) How acquired by donor.
540    pub how: String,
541    /// (f) Donor's cost or adjusted basis (money — a [`MoneyPair`] on the 2017 form).
542    pub cost: MoneyCell,
543    /// (i)/(h) Amount claimed as a deduction (carrier row only; money — a [`MoneyPair`] on 2017).
544    pub deduction: MoneyCell,
545}
546
547/// Form 8283 Section B (page 1/2, over-$5,000 property + page 2 identity) — up to 3 rows (2024/2025)
548/// or 4 rows (2017 Rev. 12-2014, `Line5A`–`Line5D`).
549#[derive(Debug, Clone, Deserialize)]
550pub struct Section8283B {
551    /// The property-type checkbox MUST be checked for BTC: **"k Digital assets"** (on-state `/11`) on
552    /// the Rev. 12-2023/2025 forms; the Rev. 12-2014 form has no digital-asset box, so 2017 uses
553    /// **"j Other"** (on-state `/9`) plus [`Self::btc_property_note`].
554    pub k_digital_assets: CheckChoice,
555    /// 2017 only: since "j Other" gives no category, the digital-asset nature is identified by a
556    /// printed note **prepended to the first row's (a) description** (e.g. "Other property: digital
557    /// asset (virtual currency)"). `None` on 2024/2025 ("k Digital assets" is self-describing).
558    #[serde(default)]
559    pub btc_property_note: Option<String>,
560    /// Part IV/III appraiser name (page 2). `None` when the revision has no printed-name field (the
561    /// Rev. 12-2014 form: the appraiser identity is the handwritten signature, left blank).
562    #[serde(default)]
563    pub appraiser_name: Option<String>,
564    /// Appraiser business address (page 2).
565    pub appraiser_address: String,
566    /// Appraiser identifying number (TIN/PTIN, page 2).
567    pub appraiser_tin: String,
568    /// Donee organization name (page 2).
569    pub donee_name: String,
570    /// Donee EIN (page 2).
571    pub donee_ein: String,
572    /// Donee address (page 2).
573    pub donee_address: String,
574    /// The rows (3 on 2024/2025, 4 on 2017) — the row count also sets the per-copy overflow cap.
575    pub rows: Vec<Section8283BRow>,
576}
577
578/// The Form 8283 (Rev. 12-2025) field map for one tax year.
579#[derive(Debug, Clone, Deserialize)]
580pub struct Form8283Map {
581    /// `"f8283"`.
582    pub form: String,
583    /// Tax year.
584    pub year: i32,
585    /// The FILER's identity — "Name(s) shown on your income tax return" + identifying number. `Option`
586    /// because the crypto slice never writes it (its 8283 rides beside a return btctax did not produce)
587    /// and the 2017/2025 maps have no verified FQNs; the FULL-return filler refuses on `None`.
588    #[serde(default)]
589    pub identity: Option<IdentityCells>,
590    /// Section A (≤ $5,000).
591    pub section_a: Section8283A,
592    /// Section B (> $5,000).
593    pub section_b: Section8283B,
594}
595
596impl Form8283Map {
597    /// Parse the committed TOML.
598    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
599        toml::from_str(toml_src)
600    }
601
602    /// The TY2025 map.
603    pub fn ty2025() -> Self {
604        Self::parse(F8283_MAP_2025).expect("bundled f8283 2025 map parses")
605    }
606
607    /// The TY2024 map (Form 8283 Rev. 12-2023).
608    pub fn ty2024() -> Self {
609        Self::parse(F8283_MAP_2024).expect("bundled f8283 2024 map parses")
610    }
611
612    /// The TY2017 map (Form 8283 Rev. 12-2014 — "j Other", no DA box, 5/4 rows, ¢-pairs).
613    pub fn ty2017() -> Self {
614        Self::parse(F8283_MAP_2017).expect("bundled f8283 2017 map parses")
615    }
616
617    /// The map for a supported tax year.
618    pub fn for_year(year: i32) -> Result<Self, FormsError> {
619        match year {
620            2017 => Ok(Self::ty2017()),
621            2024 => Ok(Self::ty2024()),
622            2025 => Ok(Self::ty2025()),
623            _ => Err(FormsError::UnsupportedYear(year)),
624        }
625    }
626
627    /// Every field name the map targets (for the `map_YYYY_matches_bundled_pdf_fieldset` guard).
628    pub fn field_names(&self) -> Vec<&str> {
629        let mut v = Vec::new();
630        for r in &self.section_a.rows {
631            v.extend([
632                r.donee.as_str(),
633                r.desc.as_str(),
634                r.date_contrib.as_str(),
635                r.date_acq.as_str(),
636                r.how.as_str(),
637            ]);
638            v.extend(r.cost.fields());
639            v.extend(r.fmv.fields());
640            v.push(r.method.as_str());
641        }
642        let b = &self.section_b;
643        v.push(b.k_digital_assets.field.as_str());
644        if let Some(n) = &b.appraiser_name {
645            v.push(n.as_str());
646        }
647        v.extend([
648            b.appraiser_address.as_str(),
649            b.appraiser_tin.as_str(),
650            b.donee_name.as_str(),
651            b.donee_ein.as_str(),
652            b.donee_address.as_str(),
653        ]);
654        for r in &b.rows {
655            v.extend([r.desc.as_str(), r.date_acq.as_str(), r.how.as_str()]);
656            v.extend(r.fmv.fields());
657            v.extend(r.cost.fields());
658            v.extend(r.deduction.fields());
659        }
660        v
661    }
662}
663
664/// One Form 8275 Part I row (Rev. 10-2024): the columns btctax actually fills, keyed to a T13
665/// `Part1Item`. **FREE-TEXT, no money-grid clustering** (arch/T15): every cell here is written via
666/// `push_free`/`FlatPlacement::free`, not the column-x-clustered `push_cell` form8283/Schedule-SE use.
667///
668/// Column (a) "Rev. Rul., Rev. Proc., etc." and column (e) "Line No." (a `/MaxLen 3` cell — far too
669/// narrow for our descriptive `Part1Item.line` string, e.g. "Part I — column (e)") are **deliberately
670/// absent**: there is no citation to disclose, and Form 8949 has no discrete numbered "line" (it is a
671/// per-transaction, lettered-COLUMN schedule) — nothing correct could be written to either.
672#[derive(Debug, Clone, Deserialize)]
673pub struct Form8275Row {
674    /// (b) "Item or Group of Items" — the position's form-location descriptor (`Part1Item.line`).
675    pub item: String,
676    /// (c) "Detailed Description of Items" — the Cohan-estimate explanation (`Part1Item.description`).
677    pub desc: String,
678    /// (d) "Form or Schedule" — the filed form the position appears on (`Part1Item.form`, e.g. "8949").
679    pub form_schedule: String,
680    /// (f) "Amount".
681    pub amount: String,
682}
683
684/// The Form 8275 (Disclosure Statement, Rev. 10-2024) field map. **One revision, aliased to every
685/// `SUPPORTED_YEAR`** — see [`F8275_MAP_2024`].
686#[derive(Debug, Clone, Deserialize)]
687pub struct Form8275Map {
688    /// `"f8275"`.
689    pub form: String,
690    /// Tax year this map instance is stamped for (re-stamped by `for_year`; the field SET is identical
691    /// across every supported year — see the module doc).
692    pub year: i32,
693    /// The FILER's identity — "Name(s) shown on return" + "Identifying number shown on return". The map
694    /// always DECLARES these cells (unlike Form 8283, whose 2017 revision structurally lacks an identity
695    /// block), but Task 16's crypto-slice fill (`fill_form_8275_slice`) leaves them unwritten — mirroring
696    /// Form 8283's own crypto-slice fill, which writes no identity either.
697    pub identity: IdentityCells,
698    /// Part I rows (6 on this revision) — the per-copy capacity `fill_form_8275` refuses beyond.
699    pub rows: Vec<Form8275Row>,
700    /// Part II "Detailed Explanation" — the single free-text field the filer's combined narrative
701    /// (`Printed8275::part_ii`) is written to whole (no per-line splitting; mirrors how form8283 writes
702    /// a whole address into one wide identity cell).
703    pub part_ii_narrative: String,
704}
705
706impl Form8275Map {
707    /// Parse the committed TOML.
708    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
709        toml::from_str(toml_src)
710    }
711
712    /// The bundled Rev. 10-2024 map, as committed (`year` field reads 2024).
713    pub fn ty2024() -> Self {
714        Self::parse(F8275_MAP_2024).expect("bundled f8275 map parses")
715    }
716
717    /// The map for a supported tax year. ★ Form 8275 is REVISION-versioned, not tax-year-versioned:
718    /// the ONE bundled Rev. 10-2024 map/asset is aliased to EVERY `SUPPORTED_YEAR` (2017/2024/2025) —
719    /// only the `year` tag is re-stamped to the caller's requested year. This is what keeps a promoted
720    /// 2025 (or 2017) disposal's Form 8275 export from being permanently refused for want of a
721    /// "2025 map" that would never structurally differ from this one.
722    pub fn for_year(year: i32) -> Result<Self, FormsError> {
723        match year {
724            2017 | 2024 | 2025 => {
725                let mut m = Self::ty2024();
726                m.year = year;
727                Ok(m)
728            }
729            _ => Err(FormsError::UnsupportedYear(year)),
730        }
731    }
732
733    /// Every field name the map targets (for the `map_YYYY_matches_bundled_pdf_fieldset` guard).
734    pub fn field_names(&self) -> Vec<&str> {
735        let mut v = vec![self.identity.name.as_str(), self.identity.ssn.as_str()];
736        for r in &self.rows {
737            v.extend([
738                r.item.as_str(),
739                r.desc.as_str(),
740                r.form_schedule.as_str(),
741                r.amount.as_str(),
742            ]);
743        }
744        v.push(self.part_ii_narrative.as_str());
745        v
746    }
747}
748
749/// The Schedule D field map for one tax year.
750#[derive(Debug, Clone, Deserialize)]
751pub struct ScheduleDMap {
752    /// `"schedule_d"`.
753    pub form: String,
754    /// Tax year.
755    pub year: i32,
756    /// The name + SSN header cells (P6.2). `Option` because this map is SHARED with the crypto-slice
757    /// path, whose 2017/2025 editions have no verified identity FQNs and no `ReturnInputs` to source an
758    /// identity from. The FULL-return filler refuses on `None` — it may not emit an unnamed form.
759    #[serde(default)]
760    pub identity: Option<IdentityCells>,
761    /// Line 3 — Part I total from Form 8949 (Box C **or Box I**): columns d,e,g,h.
762    pub line3: AmountCols,
763    /// Line 7 — net short-term gain/loss (column h).
764    pub line7_h: String,
765    /// Line 10 — Part II total from Form 8949 (Box F **or Box L**): columns d,e,g,h.
766    pub line10: AmountCols,
767    /// Line 15 — net long-term gain/loss (column h).
768    pub line15_h: String,
769    /// Line 16 — total (line 7 + line 15), column h, page 2.
770    pub line16_h: String,
771    /// L6 — short-term capital loss carryover. **PAREN box ⇒ positive magnitude.** Full-return only
772    /// (`None` on the 2017/2025 maps, which serve the crypto-slice fill).
773    #[serde(default)]
774    pub line6: Option<MoneyCell>,
775    /// L13 — capital gain distributions (Σ 1099-DIV box 2a). Full-return only.
776    #[serde(default)]
777    pub line13: Option<MoneyCell>,
778    /// L14 — long-term capital loss carryover. **PAREN box ⇒ positive magnitude.** Full-return only.
779    #[serde(default)]
780    pub line14: Option<MoneyCell>,
781    /// L18 — 28%-Rate Gain Worksheet (always 0; a nonzero amount is refused upstream). Full-return only.
782    #[serde(default)]
783    pub line18: Option<MoneyCell>,
784    /// L19 — Unrecaptured §1250 Gain Worksheet (always 0; refused upstream). Full-return only.
785    #[serde(default)]
786    pub line19: Option<MoneyCell>,
787    /// L21 — the §1211(b) allowed loss offset. **PAREN box ⇒ positive magnitude.** Full-return only.
788    #[serde(default)]
789    pub line21: Option<MoneyCell>,
790    /// L17 — "Are lines 15 and 16 both gains?" Full-return only.
791    #[serde(default)]
792    pub line17: Option<YesNoPair>,
793    /// L20 — "Are lines 18 and 19 both zero or blank…?" Full-return only.
794    #[serde(default)]
795    pub line20: Option<YesNoPair>,
796    /// L22 — "Do you have qualified dividends on Form 1040, line 3a?" Full-return only.
797    #[serde(default)]
798    pub line22: Option<YesNoPair>,
799    /// The Part I amount-column subform token used to re-derive the geometry bands — **per-year map
800    /// config** (`Table_PartI` for 2024/2025, **`TablePartI`** (no underscore) for the 2017 form).
801    #[serde(default = "default_sched_d_token")]
802    pub table_token: String,
803    /// QOF question "Yes" choice. `None` on years whose Schedule D has no QOF question (2017 —
804    /// Qualified Opportunity Funds began in 2019).
805    #[serde(default)]
806    pub qof_yes: Option<CheckChoice>,
807    /// QOF question "No" choice (answered No when present). `None` on 2017 (no QOF question).
808    #[serde(default)]
809    pub qof_no: Option<CheckChoice>,
810}
811
812/// The default Schedule D Part I grid token (2024/2025); the 2017 map overrides it to `TablePartI`.
813fn default_sched_d_token() -> String {
814    "Table_PartI".to_string()
815}
816
817impl ScheduleDMap {
818    /// Parse the committed TOML.
819    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
820        toml::from_str(toml_src)
821    }
822
823    /// The TY2025 map.
824    pub fn ty2025() -> Self {
825        Self::parse(SCHEDULE_D_MAP_2025).expect("bundled schedule_d 2025 map parses")
826    }
827
828    /// The TY2024 map.
829    pub fn ty2024() -> Self {
830        Self::parse(SCHEDULE_D_MAP_2024).expect("bundled schedule_d 2024 map parses")
831    }
832
833    /// The TY2017 map (grid token `TablePartI`; NO QOF question).
834    pub fn ty2017() -> Self {
835        Self::parse(SCHEDULE_D_MAP_2017).expect("bundled schedule_d 2017 map parses")
836    }
837
838    /// The map for a supported tax year.
839    pub fn for_year(year: i32) -> Result<Self, FormsError> {
840        match year {
841            2017 => Ok(Self::ty2017()),
842            2024 => Ok(Self::ty2024()),
843            2025 => Ok(Self::ty2025()),
844            _ => Err(FormsError::UnsupportedYear(year)),
845        }
846    }
847}
848
849/// The Form 8959 (Additional Medicare Tax) field map for one tax year.
850///
851/// Only the lines we FILL are mapped. Lines 2/3 (Form 4137 / Form 8919) and all of Part III plus
852/// line 23 (RRTA) are unmodeled and are deliberately absent — they stay blank on the filed form,
853/// which is why line 4 = line 1, line 18 = 7 + 13, and line 24 = line 22.
854#[derive(Debug, Clone, Deserialize)]
855pub struct Form8959Map {
856    /// `"f8959"`.
857    pub form: String,
858    /// Tax year.
859    pub year: i32,
860    /// The name + SSN header cells (P6.2). REQUIRED: a full-return schedule that does not name its
861    /// taxpayer is not a filable form, so a map lacking `[identity]` fails at deserialization.
862    pub identity: IdentityCells,
863    /// L1 — Σ W-2 box 5 Medicare wages, MID column.
864    pub line1: MoneyCell,
865    /// L4 — add lines 1–3 (2/3 blank ⇒ = line 1), MID column.
866    pub line4: MoneyCell,
867    /// L5 — filing-status threshold, MID column.
868    pub line5: MoneyCell,
869    /// L6 — line 4 − line 5, floored at 0, AMOUNT column.
870    pub line6: MoneyCell,
871    /// L7 — 0.9% × line 6, AMOUNT column.
872    pub line7: MoneyCell,
873    /// L8 — Schedule SE Part I line 6 (net SE earnings), MID column.
874    pub line8: MoneyCell,
875    /// L9 — filing-status threshold (again), MID column.
876    pub line9: MoneyCell,
877    /// L10 — the amount from line 4, MID column.
878    pub line10: MoneyCell,
879    /// L11 — line 9 − line 10, floored at 0, MID column.
880    pub line11: MoneyCell,
881    /// L12 — line 8 − line 11, floored at 0, AMOUNT column.
882    pub line12: MoneyCell,
883    /// L13 — 0.9% × line 12, AMOUNT column.
884    pub line13: MoneyCell,
885    /// L18 — add 7, 13, 17 → Schedule 2 line 11, AMOUNT column.
886    pub line18: MoneyCell,
887    /// L19 — Σ W-2 box 6 Medicare tax withheld, MID column.
888    pub line19: MoneyCell,
889    /// L20 — the amount from line 1, MID column.
890    pub line20: MoneyCell,
891    /// L21 — 1.45% × line 20, MID column.
892    pub line21: MoneyCell,
893    /// L22 — line 19 − line 21, floored at 0, AMOUNT column.
894    pub line22: MoneyCell,
895    /// L24 — add 22 and 23 → 1040 line 25c, AMOUNT column.
896    pub line24: MoneyCell,
897}
898
899impl Form8959Map {
900    /// Parse the committed TOML.
901    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
902        toml::from_str(toml_src)
903    }
904
905    /// The TY2024 map.
906    pub fn ty2024() -> Self {
907        Self::parse(F8959_MAP_2024).expect("bundled f8959 2024 map parses")
908    }
909
910    /// The map for a supported tax year. Full-return v1 is **TY2024-only**: Form 8959 is reachable
911    /// only from the absolute return, which itself has tables for 2024 alone.
912    pub fn for_year(year: i32) -> Result<Self, FormsError> {
913        match year {
914            2024 => Ok(Self::ty2024()),
915            _ => Err(FormsError::UnsupportedYear(year)),
916        }
917    }
918
919    /// The 17 filled cells, in **printed reading order** (strictly descending y on page 1) — the
920    /// order `fill_form_8959` walks and the ordinal the geometric verifier checks the descent of.
921    pub fn lines(&self) -> [&MoneyCell; 17] {
922        [
923            &self.line1,
924            &self.line4,
925            &self.line5,
926            &self.line6,
927            &self.line7,
928            &self.line8,
929            &self.line9,
930            &self.line10,
931            &self.line11,
932            &self.line12,
933            &self.line13,
934            &self.line18,
935            &self.line19,
936            &self.line20,
937            &self.line21,
938            &self.line22,
939            &self.line24,
940        ]
941    }
942}
943
944/// The Form 8960 (Net Investment Income Tax) field map for one tax year.
945///
946/// Only the lines v1 FILLS are mapped. Annuities (3), Schedule E (4a–4c), CFC/PFIC (6), investment
947/// expenses (9a–9c, 10) and the whole estates-and-trusts branch (18a–21) are unmodeled and stay
948/// BLANK. The derived totals 9d and 11 ARE filled at zero — the form's arithmetic adds them.
949#[derive(Debug, Clone, Deserialize)]
950pub struct Form8960Map {
951    /// `"f8960"`.
952    pub form: String,
953    /// Tax year.
954    pub year: i32,
955    /// The name + SSN header cells (P6.2). REQUIRED: a full-return schedule that does not name its
956    /// taxpayer is not a filable form, so a map lacking `[identity]` fails at deserialization.
957    pub identity: IdentityCells,
958    /// L1 — taxable interest, AMOUNT column.
959    pub line1: MoneyCell,
960    /// L2 — ordinary dividends, AMOUNT column.
961    pub line2: MoneyCell,
962    /// L5a — net gain/loss from disposition of property, MID column.
963    pub line5a: MoneyCell,
964    /// L5d — combine 5a–5c, AMOUNT column.
965    pub line5d: MoneyCell,
966    /// L7 — other modifications, AMOUNT column.
967    pub line7: MoneyCell,
968    /// L8 — total investment income, AMOUNT column.
969    pub line8: MoneyCell,
970    /// L9d — add 9a/9b/9c (zero in v1), AMOUNT column.
971    pub line9d: MoneyCell,
972    /// L11 — total deductions and modifications (zero in v1), AMOUNT column.
973    pub line11: MoneyCell,
974    /// L12 — net investment income, AMOUNT column.
975    pub line12: MoneyCell,
976    /// L13 — modified AGI, MID column.
977    pub line13: MoneyCell,
978    /// L14 — the §1411(b) threshold (fillable, NOT pre-printed), MID column.
979    pub line14: MoneyCell,
980    /// L15 — 13 − 14, floored, MID column.
981    pub line15: MoneyCell,
982    /// L16 — smaller of 12 or 15, AMOUNT column.
983    pub line16: MoneyCell,
984    /// L17 — 3.8% × 16 → Schedule 2 line 12, AMOUNT column.
985    pub line17: MoneyCell,
986}
987
988impl Form8960Map {
989    /// Parse the committed TOML.
990    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
991        toml::from_str(toml_src)
992    }
993    /// The TY2024 map.
994    pub fn ty2024() -> Self {
995        Self::parse(F8960_MAP_2024).expect("bundled f8960 2024 map parses")
996    }
997    /// The map for a supported tax year. Full-return v1 is TY2024-only.
998    pub fn for_year(year: i32) -> Result<Self, FormsError> {
999        match year {
1000            2024 => Ok(Self::ty2024()),
1001            _ => Err(FormsError::UnsupportedYear(year)),
1002        }
1003    }
1004    /// The 14 filled cells in printed reading order (strictly descending y on page 1).
1005    pub fn lines(&self) -> [&MoneyCell; 14] {
1006        [
1007            &self.line1,
1008            &self.line2,
1009            &self.line5a,
1010            &self.line5d,
1011            &self.line7,
1012            &self.line8,
1013            &self.line9d,
1014            &self.line11,
1015            &self.line12,
1016            &self.line13,
1017            &self.line14,
1018            &self.line15,
1019            &self.line16,
1020            &self.line17,
1021        ]
1022    }
1023}
1024
1025/// The Form 8995 (QBI deduction, simplified) field map for one tax year.
1026///
1027/// The Part I trade/business table (rows 1i–1v) and line 3 are deliberately unmapped: v1's only QBI
1028/// is §199A REIT dividends, so there is no business to list. Lines 2/4/5 ARE filled, at zero.
1029///
1030/// **Lines 7, 16 and 17 are PARENTHESIZED boxes — the form prints the minus sign, so the value must
1031/// be a POSITIVE MAGNITUDE.** `qbi::Form8995Lines` guarantees that.
1032#[derive(Debug, Clone, Deserialize)]
1033pub struct Form8995Map {
1034    /// `"f8995"`.
1035    pub form: String,
1036    /// Tax year.
1037    pub year: i32,
1038    /// The name + SSN header cells (P6.2). REQUIRED: a full-return schedule that does not name its
1039    /// taxpayer is not a filable form, so a map lacking `[identity]` fails at deserialization.
1040    pub identity: IdentityCells,
1041    /// Part I row 1i(a) — the trade or business's description.
1042    pub row1_business: MoneyCell,
1043    /// Part I row 1i(b) — its TIN (the filer's SSN; `/MaxLen` 11 ⇒ hyphenated).
1044    pub row1_tin: MoneyCell,
1045    /// Part I row 1i(c) — its QBI. With one business this IS line 2, which the form totals from it.
1046    pub row1_qbi: MoneyCell,
1047    /// L2 — total QBI: "Combine lines 1i through 1v, column (c)". MID column.
1048    pub line2: MoneyCell,
1049    /// L4 — combine 2 and 3, MID column.
1050    pub line4: MoneyCell,
1051    /// L5 — QBI component (20% × 4), AMOUNT column.
1052    pub line5: MoneyCell,
1053    /// L6 — qualified REIT dividends + PTP income, MID column.
1054    pub line6: MoneyCell,
1055    /// L7 — prior-year REIT/PTP loss carryforward, MID column. ★ positive magnitude (paren box).
1056    pub line7: MoneyCell,
1057    /// L8 — combine 6 and 7, MID column.
1058    pub line8: MoneyCell,
1059    /// L9 — REIT/PTP component (20% × 8), AMOUNT column.
1060    pub line9: MoneyCell,
1061    /// L10 — add 5 and 9, AMOUNT column.
1062    pub line10: MoneyCell,
1063    /// L11 — taxable income before the QBI deduction, MID column.
1064    pub line11: MoneyCell,
1065    /// L12 — net capital gain + qualified dividends, MID column.
1066    pub line12: MoneyCell,
1067    /// L13 — 11 − 12, floored, MID column.
1068    pub line13: MoneyCell,
1069    /// L14 — income limitation (20% × 13), AMOUNT column.
1070    pub line14: MoneyCell,
1071    /// L15 — the deduction: smaller of 10 or 14 → 1040 L13, AMOUNT column.
1072    pub line15: MoneyCell,
1073    /// L16 — total QB (loss) carryforward, AMOUNT column. ★ positive magnitude (paren box).
1074    pub line16: MoneyCell,
1075    /// L17 — total REIT/PTP (loss) carryforward, AMOUNT column. ★ positive magnitude (paren box).
1076    pub line17: MoneyCell,
1077}
1078
1079impl Form8995Map {
1080    /// Parse the committed TOML.
1081    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
1082        toml::from_str(toml_src)
1083    }
1084    /// The TY2024 map.
1085    pub fn ty2024() -> Self {
1086        Self::parse(F8995_MAP_2024).expect("bundled f8995 2024 map parses")
1087    }
1088    /// The map for a supported tax year. Full-return v1 is TY2024-only.
1089    pub fn for_year(year: i32) -> Result<Self, FormsError> {
1090        match year {
1091            2024 => Ok(Self::ty2024()),
1092            _ => Err(FormsError::UnsupportedYear(year)),
1093        }
1094    }
1095    /// The 15 filled cells in printed reading order (strictly descending y on page 1).
1096    pub fn lines(&self) -> [&MoneyCell; 15] {
1097        [
1098            &self.line2,
1099            &self.line4,
1100            &self.line5,
1101            &self.line6,
1102            &self.line7,
1103            &self.line8,
1104            &self.line9,
1105            &self.line10,
1106            &self.line11,
1107            &self.line12,
1108            &self.line13,
1109            &self.line14,
1110            &self.line15,
1111            &self.line16,
1112            &self.line17,
1113        ]
1114    }
1115}
1116
1117/// The Schedule 2 (Additional Taxes) field map for one tax year.
1118///
1119/// Part I is entirely absent: line 1a (excess APTC) has no input and would refuse if it did, and
1120/// line 2 (AMT) is $0 by construction (the return is refused if the Form 6251 screen trips). Only
1121/// the three Part II taxes v1 computes are mapped. **Line 21 is on PAGE 2.**
1122#[derive(Debug, Clone, Deserialize)]
1123pub struct Schedule2Map {
1124    /// `"f1040s2"`.
1125    pub form: String,
1126    /// Tax year.
1127    pub year: i32,
1128    /// The name + SSN header cells (P6.2). REQUIRED: a full-return schedule that does not name its
1129    /// taxpayer is not a filable form, so a map lacking `[identity]` fails at deserialization.
1130    pub identity: IdentityCells,
1131    /// L4 — self-employment tax (SS + regular Medicare only), AMOUNT column, page 1.
1132    pub line4: MoneyCell,
1133    /// L11 — Additional Medicare Tax (Form 8959's printed L18), AMOUNT column, page 1.
1134    pub line11: MoneyCell,
1135    /// L12 — net investment income tax (Form 8960's printed L17), AMOUNT column, page 1.
1136    pub line12: MoneyCell,
1137    /// L21 — total other taxes → 1040 L23, AMOUNT column, **page 2**.
1138    pub line21: MoneyCell,
1139}
1140
1141impl Schedule2Map {
1142    /// Parse the committed TOML.
1143    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
1144        toml::from_str(toml_src)
1145    }
1146    /// The TY2024 map.
1147    pub fn ty2024() -> Self {
1148        Self::parse(SCHEDULE_2_MAP_2024).expect("bundled schedule 2 2024 map parses")
1149    }
1150    /// The map for a supported tax year. Full-return v1 is TY2024-only.
1151    pub fn for_year(year: i32) -> Result<Self, FormsError> {
1152        match year {
1153            2024 => Ok(Self::ty2024()),
1154            _ => Err(FormsError::UnsupportedYear(year)),
1155        }
1156    }
1157    /// The 4 filled cells in printed reading order. **Descent is grouped by PAGE** — line 21 sits on
1158    /// page 2, whose y-coordinates are not comparable with page 1's.
1159    pub fn lines(&self) -> [&MoneyCell; 4] {
1160        [&self.line4, &self.line11, &self.line12, &self.line21]
1161    }
1162}
1163
1164/// The Schedule 3 (Additional Credits and Payments) field map for one tax year.
1165///
1166/// Only the foreign tax credit (L1) and the §6413(c) excess-Social-Security credit (L11) are mapped.
1167/// Every other Part I credit is a §3.4 conservative omission and stays BLANK.
1168#[derive(Debug, Clone, Deserialize)]
1169pub struct Schedule3Map {
1170    /// `"f1040s3"`.
1171    pub form: String,
1172    /// Tax year.
1173    pub year: i32,
1174    /// The name + SSN header cells (P6.2). REQUIRED: a full-return schedule that does not name its
1175    /// taxpayer is not a filable form, so a map lacking `[identity]` fails at deserialization.
1176    pub identity: IdentityCells,
1177    /// L1 — foreign tax credit, AMOUNT column.
1178    pub line1: MoneyCell,
1179    /// L8 — total nonrefundable credits → 1040 L20, AMOUNT column.
1180    pub line8: MoneyCell,
1181    /// L10 — "Amount paid with request for extension to file", AMOUNT column. ★ Its absence made the
1182    /// filed return demand a payment the filer had ALREADY made (Fable ARCH-P6.3a D1).
1183    pub line10: MoneyCell,
1184    /// L11 — excess Social Security / tier-1 RRTA withheld, AMOUNT column.
1185    pub line11: MoneyCell,
1186    /// L15 — total other payments → 1040 L31, AMOUNT column.
1187    pub line15: MoneyCell,
1188}
1189
1190impl Schedule3Map {
1191    /// Parse the committed TOML.
1192    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
1193        toml::from_str(toml_src)
1194    }
1195    /// The TY2024 map.
1196    pub fn ty2024() -> Self {
1197        Self::parse(SCHEDULE_3_MAP_2024).expect("bundled schedule 3 2024 map parses")
1198    }
1199    /// The map for a supported tax year. Full-return v1 is TY2024-only.
1200    pub fn for_year(year: i32) -> Result<Self, FormsError> {
1201        match year {
1202            2024 => Ok(Self::ty2024()),
1203            _ => Err(FormsError::UnsupportedYear(year)),
1204        }
1205    }
1206    /// The 4 filled cells in printed reading order (strictly descending y on page 1).
1207    pub fn lines(&self) -> [&MoneyCell; 5] {
1208        [
1209            &self.line1,
1210            &self.line8,
1211            &self.line10,
1212            &self.line11,
1213            &self.line15,
1214        ]
1215    }
1216}
1217
1218/// The Schedule A (Itemized Deductions) field map for one tax year.
1219///
1220/// **Three x-clusters** — Schedule A is the only form here that needs a third. Line 2 (the AGI the
1221/// 7.5% medical floor is taken on) sits INLINE with the printed sentence at x ≈ [331,403], not in the
1222/// MID column, and it is the same WIDTH as MID, so nothing but its x-position distinguishes it.
1223///
1224/// Unmapped on purpose: line 6 (other taxes), 8b/8c (mortgage not on a 1098; points), 9 (investment
1225/// interest), 15 (casualty), 16 (other). **Line 8d is a ReadOnly "Reserved for future use" widget** —
1226/// live, and it consumes a suffix number. Never write it.
1227#[derive(Debug, Clone, Deserialize)]
1228pub struct ScheduleAMap {
1229    /// `"f1040sa"`.
1230    pub form: String,
1231    /// Tax year.
1232    pub year: i32,
1233    /// L5a's §164(b)(5) sales-tax election checkbox — the election core already honours in the
1234    /// arithmetic, which the filed form never showed (ARCH-P6.3a Q7 item 3).
1235    pub check_5a_sales_tax: CheckChoice,
1236    /// ★ §2.7 — L8's §163(h)(3)(F) mixed-use-mortgage checkbox: "If you didn't use all of your home
1237    /// mortgage loan(s) to buy, build, or improve your home, check this box." Nested under
1238    /// `Line8_ReadOrder[0]`, like line 18's own read-order box.
1239    pub check_8_mixed_use: CheckChoice,
1240    /// L18's §63(e) "itemize even though less than the standard deduction" checkbox (Q7 item 4).
1241    pub check_18_elects_smaller: CheckChoice,
1242    /// The name + SSN header cells (P6.2). REQUIRED: a full-return schedule that does not name its
1243    /// taxpayer is not a filable form, so a map lacking `[identity]` fails at deserialization.
1244    pub identity: IdentityCells,
1245    /// L1 — medical and dental expenses, MID column.
1246    pub line1: MoneyCell,
1247    /// L2 — AGI. ★ **AGI-INLINE column**, not MID.
1248    pub line2: MoneyCell,
1249    /// L3 — the §213(a) 7.5% floor, MID column.
1250    pub line3: MoneyCell,
1251    /// L4 — medical allowed, AMOUNT column.
1252    pub line4: MoneyCell,
1253    /// L5a — state/local income or sales taxes, MID column.
1254    pub line5a: MoneyCell,
1255    /// L5b — real-estate taxes, MID column.
1256    pub line5b: MoneyCell,
1257    /// L5c — personal-property taxes, MID column.
1258    pub line5c: MoneyCell,
1259    /// L5d — add 5a-5c, MID column.
1260    pub line5d: MoneyCell,
1261    /// L5e — the §164(b) SALT cap, MID column.
1262    pub line5e: MoneyCell,
1263    /// L7 — add 5e and 6, AMOUNT column.
1264    pub line7: MoneyCell,
1265    /// L8a — mortgage interest on Form 1098, MID column.
1266    pub line8a: MoneyCell,
1267    /// L8e — add 8a-8c, MID column.
1268    pub line8e: MoneyCell,
1269    /// L10 — add 8e and 9, AMOUNT column.
1270    pub line10: MoneyCell,
1271    /// L11 — gifts by cash or check, MID column.
1272    pub line11: MoneyCell,
1273    /// L12 — gifts other than cash (incl. crypto), MID column.
1274    pub line12: MoneyCell,
1275    /// L13 — prior-year carryover, MID column.
1276    pub line13: MoneyCell,
1277    /// L14 — add 11-13, AMOUNT column.
1278    pub line14: MoneyCell,
1279    /// L17 — total itemized deductions → 1040 L12, AMOUNT column.
1280    pub line17: MoneyCell,
1281}
1282
1283impl ScheduleAMap {
1284    /// Parse the committed TOML.
1285    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
1286        toml::from_str(toml_src)
1287    }
1288    /// The TY2024 map.
1289    pub fn ty2024() -> Self {
1290        Self::parse(SCHEDULE_A_MAP_2024).expect("bundled schedule A 2024 map parses")
1291    }
1292    /// The map for a supported tax year. Full-return v1 is TY2024-only.
1293    pub fn for_year(year: i32) -> Result<Self, FormsError> {
1294        match year {
1295            2024 => Ok(Self::ty2024()),
1296            _ => Err(FormsError::UnsupportedYear(year)),
1297        }
1298    }
1299    /// The 18 filled cells in printed reading order (strictly descending y on page 1).
1300    pub fn lines(&self) -> [&MoneyCell; 18] {
1301        [
1302            &self.line1,
1303            &self.line2,
1304            &self.line3,
1305            &self.line4,
1306            &self.line5a,
1307            &self.line5b,
1308            &self.line5c,
1309            &self.line5d,
1310            &self.line5e,
1311            &self.line7,
1312            &self.line8a,
1313            &self.line8e,
1314            &self.line10,
1315            &self.line11,
1316            &self.line12,
1317            &self.line13,
1318            &self.line14,
1319            &self.line17,
1320        ]
1321    }
1322}
1323
1324/// The Schedule 1 (Additional Income and Adjustments to Income) field map for one tax year.
1325///
1326/// Root subform is `form1[0]` (as on Schedule 2), NOT `topmostSubform[0]`. **Two pages** — Part II is
1327/// entirely on page 2, so descent is grouped by page.
1328///
1329/// **Line 22 is a ReadOnly "Reserved for future use" widget** that consumes a suffix number; never
1330/// written. Non-money fields (a date on 2b, an SSN comb on 19b, a date on 19c) sit inside the money
1331/// x-band — writing a dollar amount into one prints garbage.
1332#[derive(Debug, Clone, Deserialize)]
1333pub struct Schedule1Map {
1334    /// `"f1040s1"`.
1335    pub form: String,
1336    /// Tax year.
1337    pub year: i32,
1338    /// The name + SSN header cells (P6.2). REQUIRED: a full-return schedule that does not name its
1339    /// taxpayer is not a filable form, so a map lacking `[identity]` fails at deserialization.
1340    pub identity: IdentityCells,
1341    /// L1 — taxable state/local refund, AMOUNT column, page 1.
1342    pub line1: MoneyCell,
1343    /// L3 — business income (crypto Schedule C net), AMOUNT column, page 1.
1344    pub line3: MoneyCell,
1345    /// L7 — unemployment compensation, AMOUNT column, page 1.
1346    pub line7: MoneyCell,
1347    /// L8v — digital assets received as ordinary income, **MID column**, page 1.
1348    pub line8v: MoneyCell,
1349    /// L9 — total other income, AMOUNT column, page 1.
1350    pub line9: MoneyCell,
1351    /// L10 — combine 1–7 and 9 → 1040 L8, AMOUNT column, page 1.
1352    pub line10: MoneyCell,
1353    /// L15 — deductible part of SE tax, AMOUNT column, **page 2**.
1354    pub line15: MoneyCell,
1355    /// L18 — early-withdrawal penalty, AMOUNT column, page 2.
1356    pub line18: MoneyCell,
1357    /// L21 — student-loan interest deduction, AMOUNT column, page 2.
1358    pub line21: MoneyCell,
1359    /// L26 — total adjustments → 1040 L10, AMOUNT column, page 2.
1360    pub line26: MoneyCell,
1361}
1362
1363impl Schedule1Map {
1364    /// Parse the committed TOML.
1365    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
1366        toml::from_str(toml_src)
1367    }
1368    /// The TY2024 map.
1369    pub fn ty2024() -> Self {
1370        Self::parse(SCHEDULE_1_MAP_2024).expect("bundled schedule 1 2024 map parses")
1371    }
1372    /// The map for a supported tax year. Full-return v1 is TY2024-only.
1373    pub fn for_year(year: i32) -> Result<Self, FormsError> {
1374        match year {
1375            2024 => Ok(Self::ty2024()),
1376            _ => Err(FormsError::UnsupportedYear(year)),
1377        }
1378    }
1379    /// The 10 filled cells in printed reading order. **Descent is grouped by PAGE.**
1380    pub fn lines(&self) -> [&MoneyCell; 10] {
1381        [
1382            &self.line1,
1383            &self.line3,
1384            &self.line7,
1385            &self.line8v,
1386            &self.line9,
1387            &self.line10,
1388            &self.line15,
1389            &self.line18,
1390            &self.line21,
1391            &self.line26,
1392        ]
1393    }
1394}
1395
1396/// The Schedule C (Profit or Loss From Business) field map — the crypto trade or business.
1397///
1398/// **Its money column is x ≈ [475, 576]** — not the [504, 576] of Schedules 1/2/3/A and Forms
1399/// 8959/8960/8995, and not Schedule B's [489.6, 576]. No amount-column constant is shared between
1400/// forms in this crate, and none may be.
1401///
1402/// Part II's individual expense lines (8–27b) are unmapped: v1 takes a FLAT expense total, so only
1403/// line 28 is printed. Line 30 (home office) and the line-32 at-risk checkboxes are unmapped too — a
1404/// Schedule C loss refuses upstream, so line 31 is always ≥ 0.
1405#[derive(Debug, Clone, Deserialize)]
1406pub struct ScheduleCMap {
1407    /// `"f1040sc"`.
1408    pub form: String,
1409    /// Tax year.
1410    pub year: i32,
1411    /// Line A — "Principal business or profession".
1412    pub line_a_business: String,
1413    /// Line B — the NAICS code (a 6-character comb).
1414    pub line_b_naics: String,
1415    /// Line F — the accounting-method checkboxes. `(1) Cash` and `(2) Accrual`; `(3) Other` is never
1416    /// checked (v1 captures only the two).
1417    pub method_cash: CheckChoice,
1418    pub method_accrual: CheckChoice,
1419    /// The name + SSN header cells (P6.2). REQUIRED: a full-return schedule that does not name its
1420    /// taxpayer is not a filable form, so a map lacking `[identity]` fails at deserialization.
1421    pub identity: IdentityCells,
1422    /// L1 — gross receipts or sales.
1423    pub line1: MoneyCell,
1424    /// L3 — line 1 − line 2 (returns, blank).
1425    pub line3: MoneyCell,
1426    /// L5 — gross profit (line 3 − line 4, COGS blank).
1427    pub line5: MoneyCell,
1428    /// L7 — gross income (line 5 + line 6, other income blank).
1429    pub line7: MoneyCell,
1430    /// L28 — total expenses.
1431    pub line28: MoneyCell,
1432    /// L29 — tentative profit (line 7 − line 28).
1433    pub line29: MoneyCell,
1434    /// L31 — net profit → Schedule 1 L3 **and** Schedule SE L2.
1435    pub line31: MoneyCell,
1436}
1437
1438impl ScheduleCMap {
1439    /// Parse the committed TOML.
1440    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
1441        toml::from_str(toml_src)
1442    }
1443    /// The TY2024 map.
1444    pub fn ty2024() -> Self {
1445        Self::parse(SCHEDULE_C_MAP_2024).expect("bundled schedule C 2024 map parses")
1446    }
1447    /// The map for a supported tax year. Full-return v1 is TY2024-only.
1448    pub fn for_year(year: i32) -> Result<Self, FormsError> {
1449        match year {
1450            2024 => Ok(Self::ty2024()),
1451            _ => Err(FormsError::UnsupportedYear(year)),
1452        }
1453    }
1454    /// The 7 filled cells in printed reading order (strictly descending y on page 1).
1455    pub fn lines(&self) -> [&MoneyCell; 7] {
1456        [
1457            &self.line1,
1458            &self.line3,
1459            &self.line5,
1460            &self.line7,
1461            &self.line28,
1462            &self.line29,
1463            &self.line31,
1464        ]
1465    }
1466}
1467
1468/// One listed-payer row on Schedule B: the payer-name text cell + the amount cell.
1469#[derive(Debug, Clone, Deserialize)]
1470pub struct ScheduleBRowMap {
1471    /// The payer-name field (a wide text cell in the PAYER column).
1472    pub payer: String,
1473    /// The amount field.
1474    pub amount: MoneyCell,
1475}
1476
1477/// A Yes/No checkbox pair (Schedule B Part III). Both boxes share the same on-states (`"1"`/`"2"`) and
1478/// the same x geometry across every pair on the form, so only the field NAME distinguishes them.
1479#[derive(Debug, Clone, Deserialize)]
1480pub struct YesNoPair {
1481    /// The "Yes" box.
1482    pub yes: CheckChoice,
1483    /// The "No" box.
1484    pub no: CheckChoice,
1485}
1486
1487/// The Schedule B (Interest and Ordinary Dividends) field map for one tax year.
1488///
1489/// **Its amount column is x ≈ [489.6, 576]** — not the [504, 576] of Schedules 1/2/3/A and Forms
1490/// 8959/8960/8995, nor Schedule C's [475, 576]. A shared constant would reject every cell.
1491///
1492/// **Row 1 of BOTH repeating tables has a different parent subform** (`Line1_ReadOrder` in Part I,
1493/// `ReadOrderControl` in Part II) while its amount sibling does not — so the rows are written out in
1494/// full in the TOML rather than interpolated. **Part I has 14 rows, Part II has 15**; the asymmetry
1495/// is real.
1496#[derive(Debug, Clone, Deserialize)]
1497pub struct ScheduleBMap {
1498    /// `"f1040sb"`.
1499    pub form: String,
1500    /// Tax year.
1501    pub year: i32,
1502    /// L7b — the foreign-country list. It IS a captured input; the claim that v1 had none was false
1503    /// (ARCH-P6.3a Q7 item 7).
1504    pub line7b_countries: String,
1505    /// The name + SSN header cells (P6.2). REQUIRED: a full-return schedule that does not name its
1506    /// taxpayer is not a filable form, so a map lacking `[identity]` fails at deserialization.
1507    pub identity: IdentityCells,
1508    /// Part I line 1 — the 14 interest-payer rows.
1509    pub part1_rows: Vec<ScheduleBRowMap>,
1510    /// L2 — add the amounts on line 1.
1511    pub line2: MoneyCell,
1512    /// L4 — line 2 − line 3 → 1040 L2b.
1513    pub line4: MoneyCell,
1514    /// Part II line 5 — the 15 dividend-payer rows.
1515    pub part2_rows: Vec<ScheduleBRowMap>,
1516    /// L6 — add the amounts on line 5 → 1040 L3b.
1517    pub line6: MoneyCell,
1518    /// L7a — the foreign-account Yes/No pair.
1519    pub line7a: YesNoPair,
1520    /// L8 — the foreign-trust Yes/No pair.
1521    pub line8: YesNoPair,
1522}
1523
1524impl ScheduleBMap {
1525    /// Parse the committed TOML.
1526    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
1527        toml::from_str(toml_src)
1528    }
1529    /// The TY2024 map.
1530    pub fn ty2024() -> Self {
1531        Self::parse(SCHEDULE_B_MAP_2024).expect("bundled schedule B 2024 map parses")
1532    }
1533    /// The map for a supported tax year. Full-return v1 is TY2024-only.
1534    pub fn for_year(year: i32) -> Result<Self, FormsError> {
1535        match year {
1536            2024 => Ok(Self::ty2024()),
1537            _ => Err(FormsError::UnsupportedYear(year)),
1538        }
1539    }
1540}
1541
1542/// The Schedule SE (Form 1040) field map for one tax year — the filled §1401 line chain.
1543#[derive(Debug, Clone, Deserialize)]
1544pub struct ScheduleSeMap {
1545    /// `"schedule_se"`.
1546    pub form: String,
1547    /// Tax year.
1548    pub year: i32,
1549    /// The identity header — "Name of person **with self-employment income**" + THAT person's SSN, i.e.
1550    /// the PROPRIETOR, not the return's joint name line. `Option` because this map is shared with the
1551    /// crypto slice (whose 2017/2025 editions have no verified identity FQNs and write no identity at
1552    /// all); the FULL-return filler refuses on `None`.
1553    #[serde(default)]
1554    pub identity: Option<IdentityCells>,
1555    /// Line 2 — net profit (net_se), amount column.
1556    pub line2: MoneyCell,
1557    /// Line 3 — combine 1a/1b/2 (= line 2), amount column.
1558    pub line3: MoneyCell,
1559    /// Line 4a — net SE earnings (base = net_se × 92.35%), amount column.
1560    pub line4a: MoneyCell,
1561    /// Line 4c — combine 4a/4b (= line 4a), amount column. The $400 STOP threshold.
1562    pub line4c: MoneyCell,
1563    /// Line 6 — add 4c/5b (= line 4c), amount column.
1564    pub line6: MoneyCell,
1565    /// Line 8a — Form W-2 Social Security wages, **MID column**.
1566    pub line8a: MoneyCell,
1567    /// Line 8d — add 8a/8b/8c (= line 8a), amount column.
1568    pub line8d: MoneyCell,
1569    /// Line 9 — line 7 (`ss_wage_base` constant) − line 8d, amount column.
1570    pub line9: MoneyCell,
1571    /// Line 10 — Social Security portion (`ss`), amount column.
1572    pub line10: MoneyCell,
1573    /// Line 11 — regular Medicare portion (`medicare`), amount column.
1574    pub line11: MoneyCell,
1575    /// Line 12 — SE tax = line 10 + line 11 (**SS + regular Medicare ONLY**), amount column.
1576    pub line12: MoneyCell,
1577    /// Line 13 — one-half SE-tax deduction (= line 12 × 50% = `deductible_half`), **MID column**.
1578    pub line13: MoneyCell,
1579    /// Fields the BLANK form already carries a factory `/V` for (the 2017 §B long form pre-prints
1580    /// line 7 = `127,200`/`00` and line 14 = `5,200`/`00`) — excluded from the `no_unmapped_filled`
1581    /// guard so those constants don't read as stray writes. Empty on 2024/2025.
1582    #[serde(default)]
1583    pub prefilled_exempt: Vec<String>,
1584}
1585
1586impl ScheduleSeMap {
1587    /// Parse the committed TOML.
1588    pub fn parse(toml_src: &str) -> Result<Self, toml::de::Error> {
1589        toml::from_str(toml_src)
1590    }
1591
1592    /// The TY2025 map.
1593    pub fn ty2025() -> Self {
1594        Self::parse(SCHEDULE_SE_MAP_2025).expect("bundled schedule_se 2025 map parses")
1595    }
1596
1597    /// The TY2024 map (field-name-identical to 2025; only the wage base differs).
1598    pub fn ty2024() -> Self {
1599        Self::parse(SCHEDULE_SE_MAP_2024).expect("bundled schedule_se 2024 map parses")
1600    }
1601
1602    /// The TY2017 map (OLD §B long form: dollars+cents pairs; pre-filled line 7/14 exempt).
1603    pub fn ty2017() -> Self {
1604        Self::parse(SCHEDULE_SE_MAP_2017).expect("bundled schedule_se 2017 map parses")
1605    }
1606
1607    /// The map for a supported tax year.
1608    pub fn for_year(year: i32) -> Result<Self, FormsError> {
1609        match year {
1610            2017 => Ok(Self::ty2017()),
1611            2024 => Ok(Self::ty2024()),
1612            2025 => Ok(Self::ty2025()),
1613            _ => Err(FormsError::UnsupportedYear(year)),
1614        }
1615    }
1616
1617    /// The 12 filled line cells, in chain order.
1618    pub fn lines(&self) -> [&MoneyCell; 12] {
1619        [
1620            &self.line2,
1621            &self.line3,
1622            &self.line4a,
1623            &self.line4c,
1624            &self.line6,
1625            &self.line8a,
1626            &self.line8d,
1627            &self.line9,
1628            &self.line10,
1629            &self.line11,
1630            &self.line12,
1631            &self.line13,
1632        ]
1633    }
1634
1635    /// Every field name the map targets (for the `map_YYYY_matches_bundled_pdf_fieldset` guard) —
1636    /// both members of each dollars+cents pair on the 2017 form.
1637    pub fn field_names(&self) -> Vec<&str> {
1638        self.lines().iter().flat_map(|c| c.fields()).collect()
1639    }
1640}