/**
 * @file cmd_data.c
 * @author Michal Vasko <mvasko@cesnet.cz>
 * @author Radek Krejci <rkrejci@cesnet.cz>
 * @brief 'data' command of the libyang's yanglint tool.
 *
 * Copyright (c) 2015-2020 CESNET, z.s.p.o.
 *
 * This source code is licensed under BSD 3-Clause License (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/BSD-3-Clause
 */

#define _GNU_SOURCE

#include "cmd.h"

#include <errno.h>
#include <getopt.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>

#include "libyang.h"

#include "common.h"

static void
cmd_data_help_header(void)
{
    printf("Usage: data [-emn] [-t TYPE]\n"
            "            [-F FORMAT] [-f FORMAT] [-d DEFAULTS] [-o OUTFILE] <data1> ...\n"
            "       data [-n] -t (rpc | notif | reply) [-O FILE]\n"
            "            [-F FORMAT] [-f FORMAT] [-d DEFAULTS] [-o OUTFILE] <data1> ...\n"
            "       data [-en] [-t TYPE] [-F FORMAT] -x XPATH [-o OUTFILE] <data1> ...\n"
            "                  Parse, validate and optionally print data instances\n");
}

static void
cmd_data_help_type(void)
{
    printf("  -t TYPE, --type=TYPE\n"
            "                Specify data tree type in the input data file(s):\n"
            "        data          - Complete datastore with status data (default type).\n"
            "        config        - Configuration datastore (without status data).\n"
            "        get           - Result of the NETCONF <get> operation.\n"
            "        getconfig     - Result of the NETCONF <get-config> operation.\n"
            "        edit          - Content of the NETCONF <edit-config> operation.\n"
            "        rpc           - Content of the NETCONF <rpc> message, defined as YANG's\n"
            "                        RPC/Action input statement.\n"
            "        nc-rpc        - Similar to 'rpc' but expect and check also the NETCONF\n"
            "                        envelopes <rpc> or <action>.\n"
            "        reply         - Reply to the RPC/Action. Note that the reply data are\n"
            "                        expected inside a container representing the original\n"
            "                        RPC/Action. This is necessary to identify appropriate\n"
            "                        data definitions in the schema module.\n"
            "        nc-reply      - Similar to 'reply' but expect and check also the NETCONF\n"
            "                        envelope <rpc-reply> with output data nodes as direct\n"
            "                        descendants. The original RPC/action invocation is expected\n"
            "                        in a separate parameter '-R' and is parsed as 'nc-rpc'.\n"
            "        notif         - Notification instance (content of the <notification>\n"
            "                        element without <eventTime>).\n"
            "        nc-notif      - Similar to 'notif' but expect and check also the NETCONF\n"
            "                        envelope <notification> with element <eventTime> and its\n"
            "                        sibling as the actual notification.\n");
}

static void
cmd_data_help_format(void)
{
    printf("  -f FORMAT, --format=FORMAT\n"
            "                Print the data in one of the following formats:\n"
            "                xml, json, lyb\n"
            "                Note that the LYB format requires the -o option specified.\n");
}

static void
cmd_data_help_in_format(void)
{
    printf("  -F FORMAT, --in-format=FORMAT\n"
            "                Load the data in one of the following formats:\n"
            "                xml, json, lyb\n"
            "                If input format not specified, it is detected from the file extension.\n");
}

static void
cmd_data_help_default(void)
{
    printf("  -d MODE, --default=MODE\n"
            "                Print data with default values, according to the MODE\n"
            "                (to print attributes, ietf-netconf-with-defaults model\n"
            "                must be loaded):\n"
            "      all             - Add missing default nodes.\n"
            "      all-tagged      - Add missing default nodes and mark all the default\n"
            "                        nodes with the attribute.\n"
            "      trim            - Remove all nodes with a default value.\n"
            "      implicit-tagged - Add missing nodes and mark them with the attribute.\n");
}

static void
cmd_data_help_xpath(void)
{
    printf("  -x XPATH, --xpath=XPATH\n"
            "                Evaluate XPATH expression and print the nodes satysfying the.\n"
            "                expression. The output format is specific and the option cannot\n"
            "                be combined with the -f and -d options. Also all the data\n"
            "                inputs are merged into a single data tree where the expression\n"
            "                is evaluated, so the -m option is always set implicitly.\n");
}

void
cmd_data_help(void)
{
    cmd_data_help_header();
    printf("\n");
    cmd_data_help_type();
    printf("  -e, --present Validate only with the schema modules whose data actually\n"
            "                exist in the provided input data files. Takes effect only\n"
            "                with the 'data' or 'config' TYPEs. Used to avoid requiring\n"
            "                mandatory nodes from modules which data are not present in the\n"
            "                provided input data files.\n"
            "  -m, --merge   Merge input data files into a single tree and validate at\n"
            "                once.The option has effect only for 'data' and 'config' TYPEs.\n"
            "                In case of using -x option, the data are always merged.\n"
            "  -n, --not-strict\n"
            "                Do not require strict data parsing (silently skip unknown data),\n"
            "                has no effect for schemas.\n"
            "  -O FILE, --operational=FILE\n"
            "                Provide optional data to extend validation of the 'rpc',\n"
            "                'reply' or 'notif' TYPEs. The FILE is supposed to contain\n"
            "                the operational datastore referenced from the operation.\n"
            "                In case of a nested notification or action, its parent\n"
            "                existence is also checked in these operational data.\n"
            "  -R FILE, --reply-rpc=FILE\n"
            "                Provide source RPC for parsing of the 'nc-reply' TYPE. The FILE\n"
            "                is supposed to contain the source 'nc-rpc' operation of the reply.\n");
    cmd_data_help_format();
    cmd_data_help_in_format();
    printf("  -o OUTFILE, --output=OUTFILE\n"
            "                Write the output to OUTFILE instead of stdout.\n");
    cmd_data_help_xpath();
    printf("\n");
}

void
cmd_data(struct ly_ctx **ctx, const char *cmdline)
{
    int argc = 0;
    char **argv = NULL;
    int opt, opt_index;
    struct option options[] = {
        {"defaults",    required_argument, NULL, 'd'},
        {"present",     no_argument,       NULL, 'e'},
        {"format",      required_argument, NULL, 'f'},
        {"in-format",   required_argument, NULL, 'F'},
        {"help",        no_argument,       NULL, 'h'},
        {"merge",       no_argument,       NULL, 'm'},
        {"output",      required_argument, NULL, 'o'},
        {"operational", required_argument, NULL, 'O'},
        {"reply-rpc",   required_argument, NULL, 'R'},
        {"not-strict",  no_argument,       NULL, 'n'},
        {"type",        required_argument, NULL, 't'},
        {"xpath",       required_argument, NULL, 'x'},
        {NULL, 0, NULL, 0}
    };

    uint8_t data_merge = 0;
    uint32_t options_print = 0;
    uint32_t options_parse = YL_DEFAULT_DATA_PARSE_OPTIONS;
    uint32_t options_validate = YL_DEFAULT_DATA_VALIDATE_OPTIONS;
    enum lyd_type data_type = 0;
    uint8_t data_type_set = 0;
    LYD_FORMAT outformat = LYD_UNKNOWN;
    LYD_FORMAT informat = LYD_UNKNOWN;
    struct ly_out *out = NULL;
    struct cmdline_file *operational = NULL;
    struct cmdline_file *reply_rpc = NULL;
    struct ly_set inputs = {0};
    struct ly_set xpaths = {0};

    if (parse_cmdline(cmdline, &argc, &argv)) {
        goto cleanup;
    }

    while ((opt = getopt_long(argc, argv, commands[CMD_DATA].optstring, options, &opt_index)) != -1) {
        switch (opt) {
        case 'd': /* --default */
            if (!strcasecmp(optarg, "all")) {
                options_print = (options_print & ~LYD_PRINT_WD_MASK) | LYD_PRINT_WD_ALL;
            } else if (!strcasecmp(optarg, "all-tagged")) {
                options_print = (options_print & ~LYD_PRINT_WD_MASK) | LYD_PRINT_WD_ALL_TAG;
            } else if (!strcasecmp(optarg, "trim")) {
                options_print = (options_print & ~LYD_PRINT_WD_MASK) | LYD_PRINT_WD_TRIM;
            } else if (!strcasecmp(optarg, "implicit-tagged")) {
                options_print = (options_print & ~LYD_PRINT_WD_MASK) | LYD_PRINT_WD_IMPL_TAG;
            } else {
                YLMSG_E("Unknown default mode %s\n", optarg);
                cmd_data_help_default();
                goto cleanup;
            }
            break;
        case 'f': /* --format */
            if (!strcasecmp(optarg, "xml")) {
                outformat = LYD_XML;
            } else if (!strcasecmp(optarg, "json")) {
                outformat = LYD_JSON;
            } else if (!strcasecmp(optarg, "lyb")) {
                outformat = LYD_LYB;
            } else {
                YLMSG_E("Unknown output format %s\n", optarg);
                cmd_data_help_format();
                goto cleanup;
            }
            break;
        case 'F': /* --in-format */
            if (!strcasecmp(optarg, "xml")) {
                informat = LYD_XML;
            } else if (!strcasecmp(optarg, "json")) {
                informat = LYD_JSON;
            } else if (!strcasecmp(optarg, "lyb")) {
                informat = LYD_LYB;
            } else {
                YLMSG_E("Unknown input format %s\n", optarg);
                cmd_data_help_in_format();
                goto cleanup;
            }
            break;
        case 'o': /* --output */
            if (out) {
                YLMSG_E("Only a single output can be specified.\n");
                goto cleanup;
            } else {
                if (ly_out_new_filepath(optarg, &out)) {
                    YLMSG_E("Unable open output file %s (%s)\n", optarg, strerror(errno));
                    goto cleanup;
                }
            }
            break;
        case 'O': { /* --operational */
            struct ly_in *in;
            LYD_FORMAT f = LYD_UNKNOWN;

            if (operational) {
                YLMSG_E("The operational datastore (-O) cannot be set multiple times.\n");
                goto cleanup;
            }
            if (get_input(optarg, NULL, &f, &in)) {
                goto cleanup;
            }
            operational = fill_cmdline_file(NULL, in, optarg, f);
            break;
        } /* case 'O' */
        case 'R': { /* --reply-rpc */
            struct ly_in *in;
            LYD_FORMAT f = LYD_UNKNOWN;

            if (reply_rpc) {
                YLMSG_E("The PRC of the reply (-R) cannot be set multiple times.\n");
                goto cleanup;
            }
            if (get_input(optarg, NULL, &f, &in)) {
                goto cleanup;
            }
            reply_rpc = fill_cmdline_file(NULL, in, optarg, f);
            break;
        } /* case 'R' */
        case 'e': /* --present */
            options_validate |= LYD_VALIDATE_PRESENT;
            break;
        case 'm': /* --merge */
            data_merge = 1;
            break;
        case 'n': /* --not-strict */
            options_parse &= ~LYD_PARSE_STRICT;
            break;
        case 't': /* --type */
            if (data_type_set) {
                YLMSG_E("The data type (-t) cannot be set multiple times.\n");
                goto cleanup;
            }

            if (!strcasecmp(optarg, "config")) {
                options_parse |= LYD_PARSE_NO_STATE;
                options_validate |= LYD_VALIDATE_NO_STATE;
            } else if (!strcasecmp(optarg, "get")) {
                options_parse |= LYD_PARSE_ONLY;
            } else if (!strcasecmp(optarg, "getconfig") || !strcasecmp(optarg, "get-config") || !strcasecmp(optarg, "edit")) {
                options_parse |= LYD_PARSE_ONLY | LYD_PARSE_NO_STATE;
            } else if (!strcasecmp(optarg, "rpc") || !strcasecmp(optarg, "action")) {
                data_type = LYD_TYPE_RPC_YANG;
            } else if (!strcasecmp(optarg, "nc-rpc")) {
                data_type = LYD_TYPE_RPC_NETCONF;
            } else if (!strcasecmp(optarg, "reply") || !strcasecmp(optarg, "rpcreply")) {
                data_type = LYD_TYPE_REPLY_YANG;
            } else if (!strcasecmp(optarg, "nc-reply")) {
                data_type = LYD_TYPE_REPLY_NETCONF;
            } else if (!strcasecmp(optarg, "notif") || !strcasecmp(optarg, "notification")) {
                data_type = LYD_TYPE_NOTIF_YANG;
            } else if (!strcasecmp(optarg, "nc-notif")) {
                data_type = LYD_TYPE_NOTIF_NETCONF;
            } else if (!strcasecmp(optarg, "data")) {
                /* default option */
            } else {
                YLMSG_E("Unknown data tree type %s.\n", optarg);
                cmd_data_help_type();
                goto cleanup;
            }

            data_type_set = 1;
            break;

        case 'x': /* --xpath */
            if (ly_set_add(&xpaths, optarg, 0, NULL)) {
                YLMSG_E("Storing XPath \"%s\" failed.\n", optarg);
                goto cleanup;
            }
            break;

        case 'h': /* --help */
            cmd_data_help();
            goto cleanup;
        default:
            YLMSG_E("Unknown option.\n");
            goto cleanup;
        }
    }

    if (optind == argc) {
        YLMSG_E("Missing the data file to process.\n");
        goto cleanup;
    }

    if (data_merge) {
        if (data_type || (options_parse & LYD_PARSE_ONLY)) {
            /* switch off the option, incompatible input data type */
            YLMSG_W("The --merge option has effect only for 'data' and 'config' TYPEs\n");
            data_merge = 0;
        } else {
            /* postpone validation after the merge of all the input data */
            options_parse |= LYD_PARSE_ONLY;
        }
    } else if (xpaths.count) {
        data_merge = 1;
    }

    if (xpaths.count && outformat) {
        YLMSG_E("The --format option cannot be combined with --xpath option.\n");
        cmd_data_help_xpath();
        goto cleanup;
    }
    if (xpaths.count && (options_print & LYD_PRINT_WD_MASK)) {
        YLMSG_E("The --default option cannot be combined with --xpath option.\n");
        cmd_data_help_xpath();
        goto cleanup;
    }

    if (operational && !data_type) {
        YLMSG_W("Operational datastore takes effect only with RPCs/Actions/Replies/Notifications input data types.\n");
        free_cmdline_file(operational);
        operational = NULL;
    }

    if (reply_rpc && (data_type != LYD_TYPE_REPLY_NETCONF)) {
        YLMSG_W("Source RPC is needed only for NETCONF Reply input data type.\n");
        free_cmdline_file(operational);
        operational = NULL;
    } else if (!reply_rpc && (data_type == LYD_TYPE_REPLY_NETCONF)) {
        YLMSG_E("Missing source RPC (-R) for NETCONF Reply input data type.\n");
        goto cleanup;
    }

    /* process input data files provided as standalone command line arguments */
    for (int i = 0; i < argc - optind; i++) {
        struct ly_in *in;

        if (get_input(argv[optind + i], NULL, &informat, &in)) {
            goto cleanup;
        }

        if (!fill_cmdline_file(&inputs, in, argv[optind + i], informat)) {
            ly_in_free(in, 1);
            goto cleanup;
        }
    }

    /* default output stream */
    if (!out) {
        if (ly_out_new_file(stdout, &out)) {
            YLMSG_E("Unable to set stdout as output.\n");
            goto cleanup;
        }
    }

    /* parse, validate and print data */
    if (process_data(*ctx, data_type, data_merge, outformat, out, options_parse, options_validate, options_print,
            operational, reply_rpc, &inputs, &xpaths)) {
        goto cleanup;
    }

cleanup:
    ly_out_free(out, NULL, 0);
    ly_set_erase(&inputs, free_cmdline_file);
    ly_set_erase(&xpaths, NULL);
    free_cmdline_file(operational);
    free_cmdline(argv);
}
