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

mod create_client;
mod create_company;
mod create_invoice;
mod create_job;
mod create_tag;
mod create_worker;

use create_client::CreateClient;
use create_company::CreateCompany;
use create_invoice::CreateInvoice;
use create_job::CreateJob;
use create_tag::CreateTag;
use create_worker::CreateWorker;

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

#[derive(Subcommand)]
pub(crate) enum CreateCommand {
    /// Create your company
    Company(CreateCompany),
    /// Create a new worker
    Worker(CreateWorker),
    /// Create a new client
    Client(CreateClient),
    /// Create a new job
    Job(CreateJob),
    /// Create a new tag
    Tag(CreateTag),
    /// Create an invoice from one or more jobs
    Invoice(CreateInvoice),
}

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