use crate::{
    database::Database,
    entities::{Client, Invoice, Job, Tag, Worker},
    jobber::{Deleted, JobberIter},
};

impl JobberIter for Database {
    fn iter_workers(&self, deleted: Deleted) -> impl Iterator<Item = (&String, &Worker)> {
        self.workers
            .iter()
            .filter(move |(_, worker)| deleted.check(worker.deleted))
    }

    fn iter_clients(&self, deleted: Deleted) -> impl Iterator<Item = (&String, &Client)> {
        self.clients
            .iter()
            .filter(move |(_, client)| deleted.check(client.deleted))
    }

    fn iter_jobs(&self, deleted: Deleted) -> impl Iterator<Item = (usize, &Job)> {
        self.jobs
            .iter()
            .enumerate()
            .filter(move |(_, job)| deleted.check(job.deleted))
    }

    fn iter_tags(&self, deleted: Deleted) -> impl Iterator<Item = (&String, &Tag)> {
        self.tags
            .iter()
            .filter(move |(_, tag)| deleted.check(tag.deleted))
    }

    fn iter_invoices(&self, deleted: Deleted) -> impl Iterator<Item = (usize, &Invoice)> {
        self.invoices
            .iter()
            .enumerate()
            .filter(move |(_, invoice)| deleted.check(invoice.deleted))
    }
}
