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

mod restore_client;
mod restore_invoice;
mod restore_job;
mod restore_tag;
mod restore_work;
mod restore_worker;

use restore_client::RestoreClient;
use restore_invoice::RestoreInvoice;
use restore_job::RestoreJob;
use restore_tag::RestoreTag;
use restore_work::RestoreWork;
use restore_worker::RestoreWorker;

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

#[derive(Subcommand)]
pub(crate) enum RestoreCommand {
    Worker(RestoreWorker),
    Client(RestoreClient),
    Job(RestoreJob),
    Tag(RestoreTag),
    Invoice(RestoreInvoice),
    Work(RestoreWork),
}

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