use crate::error::FormsError;
use btctax_core::tax::packet::PrintedReturn;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NamedForm {
pub name: String,
pub attachment_sequence: Option<&'static str>,
pub bytes: Vec<u8>,
}
pub fn fill_full_return(pr: &PrintedReturn, year: i32) -> Result<Vec<NamedForm>, FormsError> {
let PrintedReturn {
header,
filing_status,
forms:
btctax_core::tax::packet::PrintedForms {
f1040,
sch_1,
sch_2,
sch_3,
sch_a,
sch_b,
sch_c,
sch_d,
f8949,
sch_se,
f8959,
f8960,
f8995,
f8283,
f8275,
},
} = pr;
let mut out: Vec<NamedForm> = Vec::new();
let mut push = |name: &str, seq: Option<&'static str>, bytes: Vec<u8>| {
out.push(NamedForm {
name: name.to_string(),
attachment_sequence: seq,
bytes,
});
};
push(
"f1040",
None,
crate::fill_form_1040_full(f1040, header, *filing_status, year)?,
);
if let Some(l) = sch_1 {
push(
"f1040s1",
Some("01"),
crate::fill_schedule_1(l, header, year)?,
);
}
if let Some(l) = sch_2 {
push(
"f1040s2",
Some("02"),
crate::fill_schedule_2(l, header, year)?,
);
}
if let Some(l) = sch_3 {
push(
"f1040s3",
Some("03"),
crate::fill_schedule_3(l, header, year)?,
);
}
if let Some(l) = sch_a {
push(
"f1040sa",
Some("07"),
crate::fill_schedule_a(l, header, year)?,
);
}
if let Some(l) = sch_b {
push(
"f1040sb",
Some("08"),
crate::fill_schedule_b(l, header, year)?,
);
}
if let Some(l) = sch_c {
push(
"f1040sc",
Some("09"),
crate::fill_schedule_c(l, header, year)?,
);
}
if sch_d.must_file() {
push(
"schedule_d",
Some("12"),
crate::fill_schedule_d_full(sch_d, header, year)?,
);
if let Some(p) = f8949 {
push(
"f8949",
Some("12A"),
crate::fill_8949_full(p, header, year)?,
);
}
}
if let Some(l) = sch_se {
push(
"schedule_se",
Some("17"),
crate::fill_schedule_se_full(l, header, year)?,
);
}
if let Some(l) = f8995 {
push("f8995", Some("55"), crate::fill_form_8995(l, header, year)?);
}
if let Some(bytes) = crate::fill_form_8959(f8959, header, year)? {
push("f8959", Some("71"), bytes);
}
if let Some(l) = f8960 {
push("f8960", Some("72"), crate::fill_form_8960(l, header, year)?);
}
if let Some(p) = f8275 {
if let Some(bytes) = crate::fill_form_8275(p, header, year)? {
push("f8275", Some("92"), bytes);
}
}
if let Some(rows) = f8283 {
if let Some(bytes) = crate::fill_form_8283_full(rows, header, year)? {
push("f8283", Some("155"), bytes);
}
}
Ok(out)
}