//
// imag - the personal information management suite for the commandline
// Copyright (C) 2015-2020 Matthias Beyer <mail@beyermatthias.de> and contributors
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; version
// 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//

use std::path::PathBuf;

use clap::{Arg, ArgMatches, App, SubCommand};
use failure::Fallible as Result;

use libimagstore::storeid::StoreId;
use libimagstore::storeid::IntoStoreId;
use libimagrt::runtime::IdPathProvider;

pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
    app
        .arg(Arg::with_name("id")
             .index(1)
             .takes_value(true)
             .required(false)
             .multiple(true)
             .help("The id of the entry/entries to edit")
             .value_name("ENTRY"))

        .arg(Arg::with_name("list-id")
             .long("list-id")
             .takes_value(false)
             .required(false)
             .multiple(false)
             .help("List Store Id in output (format: '<id> - <value>'"))
        .arg(Arg::with_name("list-id-format")
             .long("list-id-format")
             .takes_value(true)
             .required(false)
             .multiple(false)
             .help("List Store Id in output with format"))

        .subcommand(SubCommand::with_name("read")
                    .about("Read a header value by path")
                    .version("0.1")
                    .arg(Arg::with_name("header-value-path")
                         .index(1)
                         .takes_value(true)
                         .required(true)
                         .multiple(false)
                         .help("Path of the header value")
                         .value_name("PATH"))
                   )

        .subcommand(SubCommand::with_name("has")
                    .about("Check whether a header value is present")
                    .version("0.1")
                    .arg(Arg::with_name("header-value-path")
                         .index(1)
                         .takes_value(true)
                         .required(true)
                         .multiple(false)
                         .help("Path of the header value")
                         .value_name("PATH"))
                   )

        .subcommand(SubCommand::with_name("hasnt")
                    .about("Check whether a header value is not present")
                    .version("0.1")
                    .arg(Arg::with_name("header-value-path")
                         .index(1)
                         .takes_value(true)
                         .required(true)
                         .multiple(false)
                         .help("Path of the header value")
                         .value_name("PATH"))
                   )

        .subcommand(SubCommand::with_name("int")
                    .about("Check whether a header value is a number")
                    .version("0.1")
                    .arg(Arg::with_name("header-value-path")
                         .index(1)
                         .takes_value(true)
                         .required(true)
                         .multiple(false)
                         .help("Path of the header value")
                         .value_name("PATH"))

                    .arg(Arg::with_name("header-int-eq")
                         .long("eq")
                         .takes_value(true)
                         .required(false)
                         .help("Check whether the value is equal to VALUE")
                         .validator(::libimagutil::cli_validators::is_integer)
                         .value_name("VALUE"))
                    .arg(Arg::with_name("header-int-neq")
                         .long