'use strict';

module.exports = () => ({
    'title': 'Service Resource Definition',
    'description': 'Defines the resources, units, metering, aggregation and rating formulas used to meter a particular service',
    'type': 'object',
    'required': ['id', 'resources', 'aggregations'],
    'properties': {
        'id': {
            'type': 'string'
        },
        'resources': {
            'type': 'array',
            'minItems': 1,
            'items': {
                'type': 'object',
                'required': ['units'],
                'properties': {
                    'name': {
                        'type': 'string'
                    },
                    'units' : {
                        'type': 'array',
                        'minItems': 1,
                        'items': {
                            'type': 'object',
                            'required': ['name', 'quantityType'],
                            'properties': {
                                'name': {
                                    'type': 'string'
                                },
                                'quantityType': {
                                    'enum' : [ 'DELTA', 'CURRENT']
                                }
                            },
                            'additionalProperties': false
                        },
                        'additionalItems': false
                    }
                },
                'additionalProperties': false
            },
            'additionalItems': false
        },
        'aggregations': {
            'type': 'array',
            'items': {
                'type': 'object',
                'required': ['id', 'unit', 'formula'],
                'properties': {
                    'id': {
                      'type': 'string'
                    },
                    'unit': {
                        'type': 'string'
                    },
                    'aggregationGroup': {
                        'type': 'object',
                        'required': ['name'],
                        'properties': {
                            'name': {
                                'enum': ['daily', 'monthly']
                            },
                            'additionalProperties': false
                        }
                    },
                    'formula': {
                    },
                    'accumulate': {
                    },
                    'aggregate': {
                    },
                    'rate': {
                    }
                },
                'additionalProperties': false
            },
            'additionalItems': false
        }
    },
    'additionalProperties':  false
});


@@ -12,56 +12,19 @@
 ';%0A%0A
-module.exports = () =%3E (%7B%0A    'title': '
+// 
 Service 
 Reso
@@ -23,17 +23,17 @@
 ice 
-R
+r
 esource 
 Defi
@@ -28,17 +28,17 @@
 esource 
-D
+d
 efinitio
@@ -42,2676 +42,1217 @@
 tion
-',%0A    'description': 'Defines the resources, units, metering, aggregation and rating formulas used to meter a particular service',%0A    'type': 'object',%0A    'required': %5B'id', 'resources', 'aggregations'%5D,%0A    'properties': %7B%0A        'id': %7B%0A            'type': 'string'%0A        %7D,%0A        'resources': %7B%0A            'type': 'array',%0A            'minItems': 1,%0A            'items': %7B%0A                'type': 'object',%0A                'required': %5B'units'%5D,%0A                'properties': %7B%0A                    'name': %7B%0A                        'type': 'string'%0A                    %7D,%0A                    'units' : %7B%0A                        'type': 'array',%0A                        'minItems': 1,%0A                        'items': %7B%0A                            'type': 'object',%0A                            'required': %5B'name', 'quantityType'%5D,%0A                            'properties': %7B%0A                                'name': %7B%0A                                    'type': 'string'%0A                                %7D,%0A                                'quantityType': %7B%0A                                    'enum' : %5B 'DELTA', 'CURRENT'%5D%0A                                %7D%0A                            %7D,%0A                            'additionalProperties': false%0A                        %7D,%0A                        'additionalItems': false%0A                    %7D%0A                %7D,%0A                'additionalProperties': false%0A            %7D,%0A            'additionalItems': false%0A        %7D,%0A        'aggregations': %7B%0A            'type': 'array',%0A            'items': %7B%0A                'type': 'object',%0A                'required': %5B'id', 'unit', 'formula'%5D,%0A                'properties': %7B%0A                    'id': %7B%0A                      'type': 'string'%0A                    %7D,%0A                    'unit': %7B%0A                        'type': 'string'%0A                    %7D,%0A                    'aggregationGroup': %7B%0A                        'type': 'object',%0A                        'required': %5B'name'%5D,%0A                        'properties': %7B%0A                            'name': %7B%0A                                'enum': %5B'daily', 'monthly'%5D%0A                            %7D,%0A                            'additionalProperties': false%0A                        %7D%0A                    %7D,%0A                    'formula': %7B%0A                    %7D,%0A                    'accumulate': %7B%0A                    %7D,%0A                    'aggregate': %7B%0A                    %7D,%0A                    'rate': %7B%0A                    %7D%0A                %7D,%0A                'additionalProperties': false%0A            %7D,%0A            'additionalItems': false%0A        %7D%0A    %7D,%0A    'additionalProperties':  false%0A%7D);%0A
+ schema%0A%0Aconst _ = require('underscore');%0A%0Aconst schema = require('cf-abacus-schema');%0A%0Aconst clone = _.clone;%0Aconst extend = _.extend;%0A%0Aconst string = schema.types.string;%0Aconst enumType = schema.types.enumType;%0Aconst object = schema.types.object;%0Aconst arrayOf = schema.types.arrayOf;%0A%0A// Unit schema%0Aconst unit = object(%7B name: string(), quantityType: enumType(%5B'DELTA', 'CURRENT'%5D) %7D, %5B'name', 'quantityType'%5D);%0A%0A// Resource schema%0Aconst resource = object(%7B name: string(), units: arrayOf(unit) %7D, %5B'units'%5D);%0A%0A// AggregationGroup schema%0Aconst aggregationGroup = object(%7B name: enumType(%5B'daily', 'monthly'%5D) %7D, %5B'name'%5D);%0A%0A// Aggregation schema%0Aconst aggregation = object(%7B id: string(), unit: string(), aggregationGroup: aggregationGroup, formula: %7B%7D, accumulate: %7B%7D, aggregate: %7B%7D, rate: %7B%7D %7D, %5B'id', 'unit', 'formula'%5D);%0A%0A// Export our public functions%0Amodule.exports = () =%3E extend(clone(object(%7B id: string(), resources: arrayOf(resource), aggregations: arrayOf(aggregation) %7D), %5B'id', 'resources', 'aggregations'%5D),%0A    %7B title: 'Service Resource Definition', description : 'Defines the resources, units, metering, accumulation, aggregation and rating formulas used to meter a particular service' %7D%0A);
 %0A

Refactor service resource definition schema to use JSON Schema primitive data type descriptor functions