use crate::commands::{Cli, Result};
use clap::{Parser, Subcommand};

mod delete_client;
mod delete_company;
mod delete_invoice;
mod delete_job;
mod delete_tag;
mod delete_work;
mod delete_worker;

use delete_client::DeleteClient;
use delete_company::DeleteCompany;
use delete_invoice::DeleteInvoice;
use delete_job::DeleteJob;
use delete_tag::DeleteTag;
use delete_work::DeleteWork;
use delete_worker::DeleteWorker;

/// Delete database entities
///
/// All the functions can be undone with `jobber undo`.
#[derive(Parser)]
pub(crate) struct Delete {
    #[command(subcommand)]
    pub(crate) command: DeleteCommand,
}

#[derive(Subcommand)]
pub(crate) enum DeleteCommand {
    Company(DeleteCompany),
    Worker(DeleteWorker),
    Client(DeleteClient),
    Job(DeleteJob),
    Tag(DeleteTag),
    Invoice(DeleteInvoice),
    Work(DeleteWork),
}

impl Delete {
    pub(crate) fn run(&self, cli: &Cli) -> Result<()> {
        match &self.command {
            DeleteCommand::Worker(delete) => delete.run(cli),
            DeleteCommand::Client(delete) => delete.run(cli),
            DeleteCommand::Job(delete) => delete.run(cli),
            DeleteCommand::Tag(delete) => delete.run(cli),
            DeleteCommand::Invoice(delete) => delete.run(cli),
            DeleteCommand::Company(delete) => delete.run(cli),
            DeleteCommand::Work(delete) => delete.run(cli),
        }
    }
}
