use crate::xlsx::XlsxReader;

pub struct XlsxToCsvLines<'a> {
    xlsx_reader: &'a XlsxReader,
    current_row: u32,
    num_rows: u32,
}

impl<'a> Iterator for XlsxToCsvLines<'a> {
    type Item = String;

    fn next(&mut self) -> Option<Self::Item> {
        if self.current_row > self.num_rows {
            return None;
        }

        let row = self.xlsx_reader.get_row(self.current_row);
        self.current_row += 1;

        let row = row.join(";");

        Some(row)
    }
}

impl XlsxReader {
    pub fn to_csv(&self) -> XlsxToCsvLines<'_> {
        let num_rows = self.get_worksheet_dimensions().1;
        XlsxToCsvLines {
            xlsx_reader: self,
            current_row: 0,
            num_rows,
        }
    }
}
