use clap::{ArgAction, Args, Subcommand};

#[derive(Debug, Args)]
#[command(args_conflicts_with_subcommands = true)]
#[command(about = "Manage member sites (as a site owner)")]
#[command(flatten_help = true)]
pub struct SiteArgs {
    #[command(subcommand)]
    pub command: Option<SiteCommands>,
}

#[derive(Debug, Subcommand)]
pub enum SiteCommands {
    #[command(about = "List Sites")]
    List,

    #[command(about = "Add Site", alias = "add")]
    Create {
        #[arg(help = "Site Name", short = 'n', long = "name", required = false)]
        name: Option<String>,

        #[arg(help = "Member Url", short = 'u', long = "url", required = false)]
        url: Option<String>,

        #[arg(
            help = "Site Description",
            short = 'd',
            long = "description",
            required = false
        )]
        description: Option<String>,

        #[arg(
            help = "Set as default",
            short = 'f',
            long = "default",
            action = ArgAction::SetTrue,
            required = false
        )]
        default_site: bool,
    },
    #[command(about = "Get Site by URL")]
    Get {
        #[arg(help = "Site URL", short = 'u', long = "site-url", required = false)]
        site_url: Option<String>,
    },
    #[command(about = "Remove Site", aliases=["remove", "destroy"])]
    Delete {
        #[arg(help = "Site URL", short = 'i', long = "site-url", required = true)]
        site_url: String,
    },
    #[command(about = "Join Ring with Invite Code", aliases=["join", "redeem"])]
    JoinRing {
        #[arg(help = "Site URL", short = 'u', long = "site-url", required = false)]
        site_url: Option<String>,

        #[arg(help = "Ring URL", short = 'r', long = "ring-url", required = true)]
        ring_url: String,

        #[arg(
            help = "Invite Code",
            short = 'c',
            long = "invite-code",
            required = true
        )]
        invite_code: String,

        #[arg(
            help = "Set as default",
            short = 'f',
            long = "default-ring",
            action = ArgAction::SetTrue,
            required = false
        )]
        default_ring: bool,
    },

    #[command(about = "Request unenrollment from a Ring", aliases=["unenroll"])]
    LeaveRing {
        #[arg(help = "Site URL", short = 'u', long = "site-url", required = false)]
        site_url: Option<String>,

        #[arg(help = "Ring URL", short = 'r', long = "ring-url", required = true)]
        ring_url: String,
    },

    #[command(about = "Generate Site Manifest")]
    Manifest {
        #[arg(help = "Site URL", short = 'u', long = "url", required = false)]
        site_url: Option<String>,
    },

    #[command(about = "Rotate Site key")]
    Rotate {
        #[arg(help = "Site URL", short = 'u', long = "url", required = false)]
        site_url: Option<String>,
    },

    #[command(about = "Set Default Site")]
    SetDefault {
        #[arg(help = "Site URL", short = 'u', long = "url", required = true)]
        site_url: String,
    },

    #[command(about = "Add a Vote to a given ring/site")]
    Vote {
        #[arg(help = "Site URL", short = 'u', long = "url", required = false)]
        url: Option<String>,

        #[arg(help = "Ring URL", short = 'r', long = "ring-url", required = false)]
        ring_url: Option<String>,

        #[arg(
            help = "Vote Subject URL",
            short = 'v',
            long = "vote-subject",
            required = true
        )]
        vote_subject: String,

        #[arg(help = "Standing", short = 's', long = "standing", required = false)]
        standing: String,

        #[arg(
            help = "Description",
            short = 'd',
            long = "description",
            required = true
        )]
        description: String,
    },

    #[command(about = "Run an interactive vote generator for all current Ring members")]
    VoteWizard {
        #[arg(help = "Site URL", short = 'u', long = "url", required = false)]
        site_url: Option<String>,
    },
}
