dpp-rules 0.14.1

Pure EU ESPR cross-field regulatory rules, shared by dpp-domain and the Wasm sector plugins
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
//! Battery recycled content validation — EU Regulation 2023/1542, Art. 8.
//!
//! Art. 8(2) and 8(3) set minimum recycled content shares for four metals, in
//! the regulation text itself. Both paragraphs require the **Annex VIII**
//! technical documentation to demonstrate the share — Annex VIII is the only
//! annex Art. 8 cross-references.
//!
//! Phase 1 (from 18 Aug 2031) covers **EV batteries, SLI batteries, and
//! industrial batteries with a capacity > 2 kWh** (excluding those with
//! exclusively external storage). **LMT batteries** join only in Phase 2 (from
//! **18 Aug 2036**), at the higher targets. Portable batteries are out of scope.
//!
//! The targets are **finalized law** — they are in the regulation text itself,
//! not in a pending delegated act. However, neither phase is yet in force, so
//! the battery plugin reports an overall status of `NotAssessed` and surfaces
//! any shortfall as an advisory warning rather than a violation. These constants
//! are the single source of truth it will check against once enforcement begins.
//!
//! ## The measurement basis differs by metal
//!
//! Art. 8(2)/(3) measure cobalt, lithium and nickel as the share recovered from
//! waste that is present **in active materials**; lead is measured as the share
//! present **in the battery**. The percentages below therefore do not share a
//! denominator, and a caller must not sum or average them across metals.
//!
//! ## Two duties, not one
//!
//! Art. 8(1) requires documentation of the *actual* shares, with no minimum,
//! from **18 Aug 2028** (industrial > 2 kWh, EV, SLI) and **18 Aug 2033** (LMT)
//! — or 24 months after the Art. 8(1) methodology delegated act enters into
//! force, whichever is later. Annex XIII point 1(e) makes that documentation
//! publicly accessible passport content. See [`art8_declaration_duty_for`].
//!
//! Art. 8(2) and 8(3) then impose *minimum* shares from 18 Aug 2031 and
//! 18 Aug 2036 — fixed dates, unconditional. See [`art8_phase_for`].
//!
//! The two ladders are independent: a battery can owe the declaration without
//! yet owing a minimum.
//!
//! ## Which phase binds is a function of the placing-on-market date
//!
//! [`art8_category_for`] maps a declared battery type and capacity onto an
//! [`Art8Category`]; [`art8_phase_for`] then picks the governing phase from the
//! date the battery was placed on the EU market. Assessment date is never an
//! input — Art. 8 attaches its duties at placing on the market, so deriving the
//! phase from "today" would report batteries lawfully placed before a phase
//! began as short of it from the moment that phase starts.
//!
//! The battery plugin calls both, and reports a missing or unparseable
//! `placedOnMarketDate` as its own finding rather than assuming one.
//!
//! ## Phase 1 — EV + SLI + industrial > 2 kWh, from **18 Aug 2031** (Art. 8(2))
//! | Material | Minimum % | Basis |
//! |----------|-----------|-------|
//! | Cobalt   |      16 % | active materials |
//! | Lead     |      85 % | the battery |
//! | Lithium  |       6 % | active materials |
//! | Nickel   |       6 % | active materials |
//!
//! ## Phase 2 — Phase 1 categories + **LMT**, from **18 Aug 2036** (Art. 8(3))
//! | Material | Minimum % | Basis |
//! |----------|-----------|-------|
//! | Cobalt   |      26 % | active materials |
//! | Lead     |      85 % | the battery |
//! | Lithium  |      12 % | active materials |
//! | Nickel   |      15 % | active materials |

use alloc::vec::Vec;

use crate::common::date::CalendarDate;

// ✅ COMPLIANCE-PIN: EU 2023/1542, Art. 8(2) and 8(3) (OJ L 191, 28.7.2023, p. 33)
// Verified verbatim against the Official Journal text on 2026-07-25. Percentages,
// dates and category scope were read directly from Art. 8(2) and 8(3); the prior
// 🟠 residual (verbatim OJ confirmation) is now closed.
// Phase-1 date: 18 Aug 2031. Phase-2 date: 18 Aug 2036.
// Category scope: Phase 1 = industrial > 2 kWh (excl. exclusively-external-storage)
// + EV + SLI. Phase 2 adds LMT. SLI is **in** Phase-1 scope.
// Cross-reference is **Annex VIII** (technical documentation), named explicitly by
// both paragraphs. A prior pin here cited "Annex X"; that annex is "LIST OF RAW
// MATERIALS AND RISK CATEGORIES" (due diligence, Arts. 48–53) and is unrelated to
// recycled content. Corrected 2026-07-25.

// ── Phase 1 constants — industrial > 2 kWh + EV + SLI, from 18 Aug 2031 ──────

/// Minimum cobalt recycled content — Art. 8(2), from 18 Aug 2031.
pub const COBALT_RECYCLED_PCT_2031: f64 = 16.0;
/// Minimum lead recycled content — Art. 8(2), from 18 Aug 2031.
pub const LEAD_RECYCLED_PCT_2031: f64 = 85.0;
/// Minimum lithium recycled content — Art. 8(2), from 18 Aug 2031.
pub const LITHIUM_RECYCLED_PCT_2031: f64 = 6.0;
/// Minimum nickel recycled content — Art. 8(2), from 18 Aug 2031.
pub const NICKEL_RECYCLED_PCT_2031: f64 = 6.0;

// ── Phase 2 constants — Phase 1 categories + LMT, from 18 Aug 2036 ───────────

/// Minimum cobalt recycled content — Art. 8(3), from 18 Aug 2036.
pub const COBALT_RECYCLED_PCT_2036: f64 = 26.0;
/// Minimum lead recycled content — Art. 8(3), from 18 Aug 2036.
pub const LEAD_RECYCLED_PCT_2036: f64 = 85.0;
/// Minimum lithium recycled content — Art. 8(3), from 18 Aug 2036.
pub const LITHIUM_RECYCLED_PCT_2036: f64 = 12.0;
/// Minimum nickel recycled content — Art. 8(3), from 18 Aug 2036.
pub const NICKEL_RECYCLED_PCT_2036: f64 = 15.0;

// ── Which phase binds ─────────────────────────────────────────────────────────

/// First day on which the Art. 8(2) minimum shares bind a battery placed on the
/// EU market — 18 August 2031.
pub const ART8_PHASE1_FROM: CalendarDate = CalendarDate::new(2031, 8, 18);

/// First day on which the Art. 8(3) minimum shares bind a battery placed on the
/// EU market — 18 August 2036.
pub const ART8_PHASE2_FROM: CalendarDate = CalendarDate::new(2036, 8, 18);

/// The battery categories Art. 8(2) and 8(3) treat differently.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Art8Category {
    /// Industrial batteries > 2 kWh (excluding those with exclusively external
    /// storage), electric-vehicle batteries, and SLI batteries. Named by both
    /// Art. 8(2) and Art. 8(3).
    IndustrialEvSli,
    /// LMT batteries. Named only by Art. 8(3) — outside Phase 1 entirely.
    Lmt,
    /// Portable batteries, and anything else Art. 8 does not reach.
    NotCovered,
}

/// Which Art. 8 minimum-share phase binds a battery.
///
/// Four outcomes, deliberately not collapsed into `Option`: "Art. 8 does not
/// reach this battery" and "Art. 8 does not reach this battery *yet*" are
/// different answers, and reporting either as a shortfall misstates an
/// operator's legal position.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Art8Phase {
    /// The minimum shares never bind this category.
    NotCovered,
    /// In scope, but placed on the market before the phase began.
    NotYetBinding,
    /// Art. 8(2) minimums apply — the `*_2031` constants.
    Phase1,
    /// Art. 8(3) minimums apply — the `*_2036` constants.
    Phase2,
}

/// Select the governing Art. 8 phase from the date the battery was **placed on
/// the EU market** — not the date of assessment.
///
/// Art. 8(2) and 8(3) attach their obligations to batteries placed on the market
/// from their respective dates. A battery lawfully placed on the market in 2030
/// does not acquire the 2031 minimums by being assessed in 2033. Passing
/// "today" here instead of the placing-on-market date produces retroactive
/// non-compliance findings from 18 Aug 2031 onwards.
#[must_use]
pub fn art8_phase_for(category: Art8Category, placed_on_market: CalendarDate) -> Art8Phase {
    match category {
        Art8Category::NotCovered => Art8Phase::NotCovered,
        // Art. 8(2) does not name LMT; only Art. 8(3) does.
        Art8Category::Lmt => {
            if placed_on_market >= ART8_PHASE2_FROM {
                Art8Phase::Phase2
            } else {
                Art8Phase::NotYetBinding
            }
        }
        Art8Category::IndustrialEvSli => {
            if placed_on_market >= ART8_PHASE2_FROM {
                Art8Phase::Phase2
            } else if placed_on_market >= ART8_PHASE1_FROM {
                Art8Phase::Phase1
            } else {
                Art8Phase::NotYetBinding
            }
        }
    }
}

/// Map a declared battery type and energy capacity onto the Art. 8 category.
///
/// Matching is case-insensitive. Art. 8(2)/(3) reach industrial batteries only
/// above 2 kWh, so an industrial battery at or below that threshold — or with an
/// undeclared capacity — is [`Art8Category::NotCovered`].
///
/// An unrecognised or absent `battery_type` maps to
/// [`Art8Category::IndustrialEvSli`]. That is the conservative direction: a
/// mislabelled in-scope battery is still assessed rather than silently skipped.
#[must_use]
pub fn art8_category_for(battery_type: &str, capacity_kwh: Option<f64>) -> Art8Category {
    let t = battery_type.trim();
    let eq = |s: &str| t.eq_ignore_ascii_case(s);
    if eq("portable") {
        Art8Category::NotCovered
    } else if eq("lmt") {
        Art8Category::Lmt
    } else if eq("industrial") {
        if capacity_kwh.is_some_and(|k| k.is_finite() && k > 2.0) {
            Art8Category::IndustrialEvSli
        } else {
            Art8Category::NotCovered
        }
    } else {
        // ev, sli / starting-lighting-ignition, and anything unrecognised.
        Art8Category::IndustrialEvSli
    }
}

// ── Input type ────────────────────────────────────────────────────────────────

/// Declared recycled content percentages for the four regulated metals.
///
/// `None` means the metal is absent or undeclared — it is skipped in target
/// checks. Only declared values can fail a target check.
#[derive(Debug, Clone, Copy)]
pub struct RecycledContentInput {
    pub cobalt_pct: Option<f64>,
    pub lithium_pct: Option<f64>,
    pub nickel_pct: Option<f64>,
    pub lead_pct: Option<f64>,
}

/// A recycled-content shortfall for a single material.
#[derive(Debug, Clone, Copy)]
pub struct RecycledContentShortfall {
    pub material: &'static str,
    pub declared_pct: f64,
    pub required_pct: f64,
}

// ── Phase-check functions ─────────────────────────────────────────────────────

/// Check declared recycled content against Art. 8(2) Phase 1 targets (from 2031).
///
/// Returns every material whose declared percentage falls below the Phase 1
/// minimum. An empty `Vec` means all declared metals pass. Undeclared metals
/// are not checked — battery-type scoping (Phase 1: EV / SLI / industrial
/// > 2 kWh; LMT only from Phase 2) is the caller's responsibility.
#[must_use]
pub fn art8_shortfalls_2031(input: &RecycledContentInput) -> Vec<RecycledContentShortfall> {
    check_targets(
        input,
        COBALT_RECYCLED_PCT_2031,
        LEAD_RECYCLED_PCT_2031,
        LITHIUM_RECYCLED_PCT_2031,
        NICKEL_RECYCLED_PCT_2031,
    )
}

/// Check declared recycled content against Art. 8(3) Phase 2 targets (from 2036).
#[must_use]
pub fn art8_shortfalls_2036(input: &RecycledContentInput) -> Vec<RecycledContentShortfall> {
    check_targets(
        input,
        COBALT_RECYCLED_PCT_2036,
        LEAD_RECYCLED_PCT_2036,
        LITHIUM_RECYCLED_PCT_2036,
        NICKEL_RECYCLED_PCT_2036,
    )
}

fn check_targets(
    input: &RecycledContentInput,
    cobalt_req: f64,
    lead_req: f64,
    lithium_req: f64,
    nickel_req: f64,
) -> Vec<RecycledContentShortfall> {
    let mut out = Vec::new();
    if let Some(pct) = input.cobalt_pct {
        // Non-finite (NaN/Inf) cannot demonstrate compliance — treat as shortfall.
        if !pct.is_finite() || pct < cobalt_req {
            out.push(RecycledContentShortfall {
                material: "cobalt",
                declared_pct: pct,
                required_pct: cobalt_req,
            });
        }
    }
    if let Some(pct) = input.lead_pct
        && (!pct.is_finite() || pct < lead_req)
    {
        out.push(RecycledContentShortfall {
            material: "lead",
            declared_pct: pct,
            required_pct: lead_req,
        });
    }
    if let Some(pct) = input.lithium_pct
        && (!pct.is_finite() || pct < lithium_req)
    {
        out.push(RecycledContentShortfall {
            material: "lithium",
            declared_pct: pct,
            required_pct: lithium_req,
        });
    }
    if let Some(pct) = input.nickel_pct
        && (!pct.is_finite() || pct < nickel_req)
    {
        out.push(RecycledContentShortfall {
            material: "nickel",
            declared_pct: pct,
            required_pct: nickel_req,
        });
    }
    out
}

// ── Chemistry → regulated-metal applicability ──────────────────────────────────

/// The Art. 8 regulated metals (cobalt, lithium, nickel, lead) that are
/// *meaningfully present* for a given battery chemistry.
///
/// Used to scope recycled-content checks so a chemistry that does not contain a
/// metal is never flagged for that metal's "shortfall" — e.g. an LFP cell
/// (LiFePO₄, no cobalt or nickel) must not produce a cobalt shortfall just
/// because the field defaulted to `0.0`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RegulatedMetals {
    pub cobalt: bool,
    pub lithium: bool,
    pub nickel: bool,
    pub lead: bool,
}

/// Map a battery chemistry code (e.g. `"LFP"`, `"NMC"`, `"lead-acid"`) to the
/// Art. 8 regulated metals it contains.
///
/// Matching is case-insensitive. Unknown chemistries return **all `true`**
/// (conservative: every declared value is checked, since we cannot rule a metal
/// out). The caller still skips any metal whose declared percentage is absent.
#[must_use]
pub fn chemistry_regulated_metals(chemistry: &str) -> RegulatedMetals {
    let c = chemistry.trim();
    let eq = |s: &str| c.eq_ignore_ascii_case(s);
    if eq("LFP") {
        RegulatedMetals {
            cobalt: false,
            lithium: true,
            nickel: false,
            lead: false,
        }
    } else if eq("NMC") || eq("NCA") {
        RegulatedMetals {
            cobalt: true,
            lithium: true,
            nickel: true,
            lead: false,
        }
    } else if eq("LCO") {
        RegulatedMetals {
            cobalt: true,
            lithium: true,
            nickel: false,
            lead: false,
        }
    } else if eq("NiMH") || eq("NiCd") {
        RegulatedMetals {
            cobalt: false,
            lithium: false,
            nickel: true,
            lead: false,
        }
    } else if eq("lead-acid") {
        RegulatedMetals {
            cobalt: false,
            lithium: false,
            nickel: false,
            lead: true,
        }
    } else if eq("solid-state") {
        RegulatedMetals {
            cobalt: false,
            lithium: true,
            nickel: false,
            lead: false,
        }
    } else {
        // Unknown chemistry — cannot exclude any metal; check whatever is declared.
        RegulatedMetals {
            cobalt: true,
            lithium: true,
            nickel: true,
            lead: true,
        }
    }
}

/// Metals whose recycled content is declared **> 0** but which the chemistry
/// does **not** contain — a data-integrity contradiction (e.g. cobalt recycled
/// content on an LFP cell, which has no cobalt).
///
/// A declared `0.0` is *not* a conflict (it states "no recycled content", which
/// is trivially true for an absent metal). Unknown chemistries contain every
/// metal per [`chemistry_regulated_metals`], so they never conflict.
#[must_use]
pub fn recycled_content_chemistry_conflicts(
    chemistry: &str,
    cobalt_pct: Option<f64>,
    lithium_pct: Option<f64>,
    nickel_pct: Option<f64>,
    lead_pct: Option<f64>,
) -> Vec<&'static str> {
    let reg = chemistry_regulated_metals(chemistry);
    let positive = |v: Option<f64>| matches!(v, Some(x) if x.is_finite() && x > 0.0);
    let mut out = Vec::new();
    if positive(cobalt_pct) && !reg.cobalt {
        out.push("cobalt");
    }
    if positive(lithium_pct) && !reg.lithium {
        out.push("lithium");
    }
    if positive(nickel_pct) && !reg.nickel {
        out.push("nickel");
    }
    if positive(lead_pct) && !reg.lead {
        out.push("lead");
    }
    out
}

#[cfg(test)]
mod tests {
    use super::*;

    fn all_metals(co: f64, pb: f64, li: f64, ni: f64) -> RecycledContentInput {
        RecycledContentInput {
            cobalt_pct: Some(co),
            lead_pct: Some(pb),
            lithium_pct: Some(li),
            nickel_pct: Some(ni),
        }
    }

    // ── Art. 8 phase selection — golden vectors ──────────────────────────────

    #[test]
    fn battery_placed_before_phase1_stays_unbound_however_late_it_is_assessed() {
        // A battery lawfully placed on the EU market on 1 Jun 2030, assessed in
        // 2033. Art. 8(2) attaches at placing on the market, so the 2031 minimums
        // never reach it. Deriving the phase from the assessment date instead
        // would report this battery as non-compliant from 18 Aug 2031 onwards.
        let placed = CalendarDate::new(2030, 6, 1);
        assert_eq!(
            art8_phase_for(Art8Category::IndustrialEvSli, placed),
            Art8Phase::NotYetBinding
        );
    }

    #[test]
    fn phase1_boundary_is_inclusive_of_18_august_2031() {
        assert_eq!(
            art8_phase_for(
                Art8Category::IndustrialEvSli,
                CalendarDate::new(2031, 8, 17)
            ),
            Art8Phase::NotYetBinding
        );
        assert_eq!(
            art8_phase_for(
                Art8Category::IndustrialEvSli,
                CalendarDate::new(2031, 8, 18)
            ),
            Art8Phase::Phase1
        );
    }

    #[test]
    fn phase2_boundary_is_inclusive_of_18_august_2036() {
        assert_eq!(
            art8_phase_for(
                Art8Category::IndustrialEvSli,
                CalendarDate::new(2036, 8, 17)
            ),
            Art8Phase::Phase1
        );
        assert_eq!(
            art8_phase_for(
                Art8Category::IndustrialEvSli,
                CalendarDate::new(2036, 8, 18)
            ),
            Art8Phase::Phase2
        );
    }

    #[test]
    fn lmt_is_outside_phase1_entirely() {
        // Art. 8(2) does not name LMT batteries; Art. 8(3) does. An LMT battery
        // placed on the market the very day Phase 1 begins is still unbound.
        assert_eq!(
            art8_phase_for(Art8Category::Lmt, CalendarDate::new(2031, 8, 18)),
            Art8Phase::NotYetBinding
        );
        assert_eq!(
            art8_phase_for(Art8Category::Lmt, CalendarDate::new(2036, 8, 18)),
            Art8Phase::Phase2
        );
    }

    #[test]
    fn out_of_scope_categories_are_never_bound() {
        // Portable batteries, at any date, including well past Phase 2.
        assert_eq!(
            art8_phase_for(Art8Category::NotCovered, CalendarDate::new(2040, 1, 1)),
            Art8Phase::NotCovered
        );
    }

    #[test]
    fn not_covered_and_not_yet_binding_are_distinguishable() {
        // The whole point of a four-outcome enum: an operator told "not covered"
        // and one told "not yet" have different obligations, and neither has a
        // shortfall.
        let portable = art8_phase_for(Art8Category::NotCovered, CalendarDate::new(2033, 1, 1));
        let early_ev = art8_phase_for(Art8Category::IndustrialEvSli, CalendarDate::new(2030, 1, 1));
        assert_ne!(portable, early_ev);
    }

    #[test]
    fn selected_phase_agrees_with_the_target_constants() {
        // 16 % cobalt clears Phase 1 and fails Phase 2. The phase selector and
        // the constants it selects between must not disagree about which set
        // is in force on a given placing-on-market date.
        let input = all_metals(16.0, 85.0, 6.0, 6.0);

        assert_eq!(
            art8_phase_for(Art8Category::IndustrialEvSli, CalendarDate::new(2032, 1, 1)),
            Art8Phase::Phase1
        );
        assert!(art8_shortfalls_2031(&input).is_empty());

        assert_eq!(
            art8_phase_for(Art8Category::IndustrialEvSli, CalendarDate::new(2037, 1, 1)),
            Art8Phase::Phase2
        );
        assert!(
            art8_shortfalls_2036(&input)
                .iter()
                .any(|s| s.material == "cobalt")
        );
    }

    // ── Category mapping ─────────────────────────────────────────────────────

    #[test]
    fn portable_is_not_covered_and_lmt_is_its_own_category() {
        assert_eq!(
            art8_category_for("portable", None),
            Art8Category::NotCovered
        );
        assert_eq!(
            art8_category_for("PORTABLE", None),
            Art8Category::NotCovered
        );
        assert_eq!(art8_category_for("lmt", None), Art8Category::Lmt);
        assert_eq!(art8_category_for(" LMT ", None), Art8Category::Lmt);
    }

    #[test]
    fn industrial_is_covered_only_above_two_kwh() {
        assert_eq!(
            art8_category_for("industrial", Some(2.5)),
            Art8Category::IndustrialEvSli
        );
        // Art. 8 says "greater than 2 kWh" — exactly 2 kWh is out.
        assert_eq!(
            art8_category_for("industrial", Some(2.0)),
            Art8Category::NotCovered
        );
        assert_eq!(
            art8_category_for("industrial", None),
            Art8Category::NotCovered
        );
        // A non-finite capacity cannot demonstrate the threshold is met.
        assert_eq!(
            art8_category_for("industrial", Some(f64::NAN)),
            Art8Category::NotCovered
        );
    }

    #[test]
    fn ev_sli_and_unknown_types_are_assessed() {
        for t in ["ev", "sli", "starting-lighting-ignition", "", "mystery"] {
            assert_eq!(
                art8_category_for(t, None),
                Art8Category::IndustrialEvSli,
                "type {t:?} should be assessed"
            );
        }
    }

    // ── Art. 8(1) declaration duty ───────────────────────────────────────────

    #[test]
    fn declaration_is_certainly_not_due_before_its_floor() {
        // The one thing that *is* knowable while the delegated act is
        // unadopted: the real date is never earlier than the floor, so anything
        // placed on the market before it definitely owes nothing yet.
        assert_eq!(
            art8_declaration_duty_for(
                Art8Category::IndustrialEvSli,
                CalendarDate::new(2028, 8, 17)
            ),
            Art8DeclarationDuty::NotYetDue {
                not_before: CalendarDate::new(2028, 8, 18)
            }
        );
    }

    #[test]
    fn declaration_is_undetermined_on_and_after_the_floor() {
        // Art. 8(1) applies from the floor "or 24 months after the date of entry
        // into force of the delegated act, whichever is the latest". The act is
        // unadopted, so on/after the floor the answer is genuinely unknown —
        // reporting it as "due" would assert a date the regulation does not set.
        let got =
            art8_declaration_duty_for(Art8Category::IndustrialEvSli, CalendarDate::new(2029, 1, 1));
        let Art8DeclarationDuty::Undetermined {
            not_before,
            empowerment,
        } = got
        else {
            panic!("expected Undetermined, got {got:?}");
        };
        assert_eq!(not_before, CalendarDate::new(2028, 8, 18));
        assert!(empowerment.contains("Art. 8(1)"));
    }

    #[test]
    fn lmt_declaration_floor_is_five_years_later() {
        // Art. 8(1) second subparagraph: LMT from 18 Aug 2033, not 2028.
        assert_eq!(
            art8_declaration_duty_for(Art8Category::Lmt, CalendarDate::new(2030, 1, 1)),
            Art8DeclarationDuty::NotYetDue {
                not_before: CalendarDate::new(2033, 8, 18)
            }
        );
        assert!(matches!(
            art8_declaration_duty_for(Art8Category::Lmt, CalendarDate::new(2034, 1, 1)),
            Art8DeclarationDuty::Undetermined { .. }
        ));
    }

    #[test]
    fn out_of_scope_categories_owe_no_declaration() {
        assert_eq!(
            art8_declaration_duty_for(Art8Category::NotCovered, CalendarDate::new(2040, 1, 1)),
            Art8DeclarationDuty::NotCovered
        );
    }

    #[test]
    fn the_declaration_and_minimum_ladders_are_independent() {
        // A battery placed on the market in 2029 is past the declaration floor
        // but years short of the Art. 8(2) minimums. Conflating the two would
        // report a shortfall against a duty that does not yet exist.
        let placed = CalendarDate::new(2029, 1, 1);
        assert!(matches!(
            art8_declaration_duty_for(Art8Category::IndustrialEvSli, placed),
            Art8DeclarationDuty::Undetermined { .. }
        ));
        assert_eq!(
            art8_phase_for(Art8Category::IndustrialEvSli, placed),
            Art8Phase::NotYetBinding
        );
    }

    // ── Target checks ────────────────────────────────────────────────────────

    #[test]
    fn exactly_at_2031_targets_passes() {
        let input = all_metals(16.0, 85.0, 6.0, 6.0);
        assert!(art8_shortfalls_2031(&input).is_empty());
    }

    #[test]
    fn above_2031_targets_passes() {
        let input = all_metals(20.0, 90.0, 10.0, 10.0);
        assert!(art8_shortfalls_2031(&input).is_empty());
    }

    #[test]
    fn below_2031_cobalt_flagged() {
        let input = all_metals(15.0, 85.0, 6.0, 6.0); // cobalt 15 < 16
        let shortfalls = art8_shortfalls_2031(&input);
        assert_eq!(shortfalls.len(), 1);
        assert_eq!(shortfalls[0].material, "cobalt");
        assert_eq!(shortfalls[0].required_pct, 16.0);
    }

    #[test]
    fn multiple_shortfalls_all_returned() {
        let input = all_metals(10.0, 80.0, 3.0, 4.0); // all below
        assert_eq!(art8_shortfalls_2031(&input).len(), 4);
    }

    #[test]
    fn undeclared_metals_not_flagged() {
        let input = RecycledContentInput {
            cobalt_pct: Some(20.0),
            lead_pct: None,
            lithium_pct: None,
            nickel_pct: None,
        };
        assert!(art8_shortfalls_2031(&input).is_empty());
    }

    #[test]
    fn phase2_stricter_than_phase1() {
        // 16% cobalt passes 2031 but fails 2036 (target 26%)
        let input = all_metals(16.0, 85.0, 6.0, 6.0);
        assert!(art8_shortfalls_2031(&input).is_empty());
        let shortfalls = art8_shortfalls_2036(&input);
        assert!(shortfalls.iter().any(|s| s.material == "cobalt"));
    }

    #[test]
    fn nan_cobalt_treated_as_shortfall() {
        let input = RecycledContentInput {
            cobalt_pct: Some(f64::NAN),
            lead_pct: None,
            lithium_pct: None,
            nickel_pct: None,
        };
        let shortfalls = art8_shortfalls_2031(&input);
        assert_eq!(shortfalls.len(), 1);
        assert_eq!(shortfalls[0].material, "cobalt");
    }

    #[test]
    fn infinity_cobalt_treated_as_shortfall() {
        let input = RecycledContentInput {
            cobalt_pct: Some(f64::INFINITY),
            lead_pct: None,
            lithium_pct: None,
            nickel_pct: None,
        };
        let shortfalls = art8_shortfalls_2031(&input);
        assert_eq!(shortfalls.len(), 1);
        assert_eq!(shortfalls[0].material, "cobalt");
    }

    #[test]
    fn lfp_regulates_lithium_only() {
        let m = chemistry_regulated_metals("LFP");
        assert!(m.lithium);
        assert!(!m.cobalt && !m.nickel && !m.lead);
        // case-insensitive
        assert_eq!(chemistry_regulated_metals("lfp"), m);
    }

    #[test]
    fn nmc_and_nca_regulate_cobalt_lithium_nickel() {
        for chem in ["NMC", "NCA"] {
            let m = chemistry_regulated_metals(chem);
            assert!(m.cobalt && m.lithium && m.nickel);
            assert!(!m.lead);
        }
    }

    #[test]
    fn lead_acid_regulates_lead_only() {
        let m = chemistry_regulated_metals("lead-acid");
        assert!(m.lead);
        assert!(!m.cobalt && !m.lithium && !m.nickel);
    }

    #[test]
    fn unknown_chemistry_checks_all_metals() {
        let m = chemistry_regulated_metals("mystery-cell");
        assert!(m.cobalt && m.lithium && m.nickel && m.lead);
    }

    #[test]
    fn positive_cobalt_on_lfp_is_a_conflict() {
        let c = recycled_content_chemistry_conflicts("LFP", Some(5.0), Some(12.0), None, None);
        assert_eq!(c.len(), 1);
        assert_eq!(c[0], "cobalt");
    }

    #[test]
    fn zero_cobalt_on_lfp_is_not_a_conflict() {
        // 0.0 declares "no recycled cobalt" — trivially true for an absent metal.
        let c = recycled_content_chemistry_conflicts("LFP", Some(0.0), Some(12.0), Some(0.0), None);
        assert!(c.is_empty(), "got: {c:?}");
    }

    #[test]
    fn nmc_cobalt_and_nickel_declared_no_conflict() {
        let c = recycled_content_chemistry_conflicts("NMC", Some(16.0), Some(6.0), Some(8.0), None);
        assert!(c.is_empty(), "got: {c:?}");
    }

    #[test]
    fn lead_declared_on_lfp_is_a_conflict() {
        let c = recycled_content_chemistry_conflicts("LFP", None, Some(12.0), None, Some(80.0));
        assert_eq!(c.len(), 1);
        assert_eq!(c[0], "lead");
    }

    #[test]
    fn unknown_chemistry_never_conflicts() {
        let c = recycled_content_chemistry_conflicts(
            "mystery",
            Some(5.0),
            Some(5.0),
            Some(5.0),
            Some(5.0),
        );
        assert!(c.is_empty());
    }
}

// ── Art. 8(1) — the declaration duty ─────────────────────────────────────────

/// Floor date for the Art. 8(1) documentation duty for industrial batteries
/// > 2 kWh, EV and SLI — 18 August 2028.
pub const ART8_DECLARATION_FLOOR_2028: CalendarDate = CalendarDate::new(2028, 8, 18);

/// Floor date for the Art. 8(1) documentation duty for LMT batteries —
/// 18 August 2033.
pub const ART8_DECLARATION_FLOOR_2033: CalendarDate = CalendarDate::new(2033, 8, 18);

/// The empowerment whose entry into force can push the Art. 8(1) duty later.
pub const ART8_DECLARATION_EMPOWERMENT: &str = "EU 2023/1542 Art. 8(1), third subparagraph — recycled content calculation,      verification and documentation format";

/// Whether the Art. 8(1) documentation duty has begun for a battery.
///
/// Unlike the Art. 8(2)/(3) minimums, whose dates are stated outright, Art. 8(1)
/// applies from *"18 August 2028 or 24 months after the date of entry into force
/// of the delegated act …, whichever is the latest"*. That act has not been
/// adopted, so the real start date is unknown — but it is never **earlier** than
/// the floor, which is enough to answer the question for anything placed on the
/// market before it.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Art8DeclarationDuty {
    /// Art. 8(1) does not reach this category.
    NotCovered,
    /// Certainly not yet owed: placed on the market before the floor date, and
    /// the real date can only be that floor or later.
    NotYetDue { not_before: CalendarDate },
    /// Cannot be determined. Placed on the market on or after the floor, but
    /// whether the duty had begun depends on when the delegated act entered
    /// into force — and it has not been adopted.
    Undetermined {
        not_before: CalendarDate,
        empowerment: &'static str,
    },
}

/// Whether a battery owes the Art. 8(1) recycled-content declaration.
///
/// Keyed on the date the battery was **placed on the EU market**, like every
/// other Art. 8 duty — not on the date of assessment.
#[must_use]
pub fn art8_declaration_duty_for(
    category: Art8Category,
    placed_on_market: CalendarDate,
) -> Art8DeclarationDuty {
    let floor = match category {
        Art8Category::NotCovered => return Art8DeclarationDuty::NotCovered,
        Art8Category::IndustrialEvSli => ART8_DECLARATION_FLOOR_2028,
        Art8Category::Lmt => ART8_DECLARATION_FLOOR_2033,
    };
    if placed_on_market < floor {
        Art8DeclarationDuty::NotYetDue { not_before: floor }
    } else {
        Art8DeclarationDuty::Undetermined {
            not_before: floor,
            empowerment: ART8_DECLARATION_EMPOWERMENT,
        }
    }
}