module sal-flat-batch {
    namespace "urn:opendaylight:flat-batch:service";
    prefix fbatch;

    import yang-ext {prefix ext; revision-date "2013-07-09";}
    import opendaylight-inventory {prefix inv;revision-date "2013-08-19";}
    import batch-common {prefix batch;revision-date "2016-03-22";}
    import sal-flows-batch {prefix f-batch;revision-date "2016-03-14";}
    import flow-node-inventory {prefix flow-inv; revision-date "2013-08-19";}
    import sal-groups-batch {prefix g-batch;revision-date "2016-03-15";}
    import opendaylight-group-types {prefix group-type;revision-date "2013-10-18";}
    import sal-meters-batch {prefix m-batch;revision-date "2016-03-16";}
    import opendaylight-meter-types {prefix meter-type;revision-date "2013-09-18";}

    description "Openflow batch flow management.";

    revision "2016-03-21" {
        description "Initial revision of batch flat service.";
    }


    rpc process-flat-batch {
        description "Process add/update/remove of items in batch towards openflow device.";
        input {
            uses "inv:node-context-ref";

            list batch {
                key batch-order;

                uses batch:batch-order-grouping;
                choice batch-choice {
                    // filled via augmentations
                }
            }
            leaf exit-on-first-error {
                description "If true then batch will execute all steps and report list of occurred errors,
                    otherwise there will be only first error reported and execution will be stop right there.";
                type boolean;
            }
        }
        output {
            list batch-failure {
                key batch-order;

                uses batch:batch-order-grouping;
                choice batch-item-id-choice {
                    // filled via augmentations
                }
            }
        }
    }

    augment "/process-flat-batch/input/batch/batch-choice" {
        ext:augment-identifier "flat-batch-flow-crud-case-aug";
        description "Openflow add/remove/update flow operation.";

        case flat-batch-add-flow-case {
            list flat-batch-add-flow {
                key batch-order;

                uses batch:batch-order-grouping;
                uses f-batch:batch-flow-input-grouping;
            }
        }
        case flat-batch-remove-flow-case {
            list flat-batch-remove-flow {
                key batch-order;

                uses batch:batch-order-grouping;
                uses f-batch:batch-flow-input-grouping;
            }
        }
        case flat-batch-update-flow-case {
            list flat-batch-update-flow {
                key batch-order;

                uses batch:batch-order-grouping;
                uses f-batch:batch-flow-input-update-grouping;
            }
        }
    }

    augment "/process-flat-batch/input/batch/batch-choice" {
        ext:augment-identifier "flat-batch-group-crud-case-aug";
        description "Openflow add/remove/update group operation.";

        case flat-batch-add-group-case {
            list flat-batch-add-group {
                key batch-order;

                uses batch:batch-order-grouping;
                uses group-type:group;
            }
        }
        case flat-batch-remove-group-case {
            list flat-batch-remove-group {
                key batch-order;

                uses batch:batch-order-grouping;
                uses group-type:group;
            }
        }
        case flat-batch-update-group-case {
            list flat-batch-update-group {
                key batch-order;

                uses batch:batch-order-grouping;
                uses g-batch:batch-group-input-update-grouping;
            }
        }
    }

    augment "/process-flat-batch/input/batch/batch-choice" {
        ext:augment-identifier "flat-batch-meter-crud-case-aug";
        description "Openflow add/remove/update meter operation.";

        case flat-batch-add-meter-case {
            list flat-batch-add-meter {
                key batch-order;

                uses batch:batch-order-grouping;
                uses meter-type:meter;
            }
        }
        case flat-batch-remove-meter-case {
            list flat-batch-remove-meter {
                key batch-order;

                uses batch:batch-order-grouping;
                uses meter-type:meter;
            }
        }
        case flat-batch-update-meter-case {
            list flat-batch-update-meter {
                key batch-order;

                uses batch:batch-order-grouping;
                uses m-batch:batch-meter-input-update-grouping;
            }
        }
    }

    augment "/process-flat-batch/output/batch-failure/batch-item-id-choice" {
        ext:augment-identifier "flat-batch-failure-ids-aug";
        description "Openflow flat batch failures - corresponding item id.";

        case flat-batch-failure-flow-id-case {
            description "case for flow-id";
            leaf flow-id {
                type flow-inv:flow-id;
            }
        }
        case flat-batch-failure-group-id-case {
            description "case for group-id";
            leaf group-id {
                type group-type:group-id;
            }
        }
        case flat-batch-failure-meter-id-case {
            description "case for meter-id";
            leaf meter-id {
                type meter-type:meter-id;
            }
        }
    }
}