
// creation of contexts
CREATE (c1:Context {name: 'Mobility', descrition: ''})
CREATE (c2:Context {name: 'Energy', descrition: ''})


// creation of layers
CREATE (l1:Layer {name: 'Smart features', type: 'Customer-facing', order: 1})
CREATE (l2:Layer {name: 'Smart services', type: 'Customer-facing', order: 2})
CREATE (l3:Layer {name: 'Supporting services', type: 'Background', order: 3})
CREATE (l4:Layer {name: 'Energy applications', type: 'Background', order: 4})
CREATE (l5:Layer {name: 'Mobility applications', type: 'Background', order: 4})
CREATE (l6:Layer {name: 'Energy infrastructure', type: 'Background', order: 5})
CREATE (l7:Layer {name: 'Mobility infrastructure', type: 'Background', order: 5})


// services in context 'Mobility'
CREATE (s1:Service {name: 'Mobility', id: '1', description: ''})
CREATE (s2:Service {name: 'Electric mobility', id: '2', description: ''})
CREATE (s3:Service {name: 'Transport management', id: '3', description: ''})
CREATE (s4:Service {name: 'Public transport', id: '4', description: ''})
CREATE (s5:Service {name: 'Driving control', id: '5', description: ''})
CREATE (s6:Service {name: 'Smart charging', id: '6', description: ''})
CREATE (s7:Service {name: 'Vehicle usage optimization', id: '7', description: ''})
CREATE (s8:Service {name: 'Route optimization', id: '8', description: ''})
CREATE (s9:Service {name: 'Trafic monitoring', id: '9', description: ''})
CREATE (s10:Service {name: 'Regenerative breaking', id: '10', description: ''})
CREATE (s11:Service {name: 'Vehicle', id: '11', description: ''})


// services in both contexts
CREATE (s12:Service {name: 'Charging device', id: '12', description: ''})
CREATE (s13:Service {name: 'Battery monitoring', id: '13', description: ''})
CREATE (s14:Service {name: 'Energy monitoring', id: '14', description: ''})
CREATE (s15:Service {name: 'Smart grid', id: '15', description: ''})
CREATE (s16:Service {name: 'Energy', id: '16', description: ''})


// services in context 'Energy'
CREATE (s17:Service {name: 'Urban planning', id: '17', description: ''})
CREATE (s18:Service {name: 'Smart buildings', id: '18', description: ''})
CREATE (s19:Service {name: 'Energy2Grid', id: '19', description: ''})
CREATE (s20:Service {name: 'Comunication with the grid', id: '20', description: ''})
CREATE (s21:Service {name: 'Optimization of energy distribution', id: '21', description: ''})
CREATE (s22:Service {name: 'Prediction of energy consumption', id: '22', description: ''})
CREATE (s23:Service {name: 'DRS', id: '23', description: ''})
CREATE (s24:Service {name: 'Data centrator', id: '24', description: ''})
CREATE (s25:Service {name: 'Data collector', id: '25', description: ''})
CREATE (s26:Service {name: 'Smart meter', id: '26', description: ''})
CREATE (s27:Service {name: 'Control energy distribution', id: '27', description: ''})
CREATE (s28:Service {name: 'Energy Data analysis software', id: '28', description: ''})
CREATE (s29:Service {name: 'Energy data collecting', id: '29', description: ''})
CREATE (s30:Service {name: 'Smart grid monitoring', id: '30', description: ''})
CREATE (s31:Service {name: 'Smart grid maintenance', id: '31', description: ''})


// Find the Context nodes
MATCH (c_mob:Context {name: 'Mobility', description: ''})
MATCH (c_eng:Context {name: 'Energy', description: ''})


// Assignment of services into a context

MATCH (s_mob:Service)
WHERE s_mob.id IN ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11']
MATCH (s_both:Service)
WHERE s_both.id IN ['12', '13', '14', '15', '16']
MATCH (s_eng:Service)
WHERE s_eng.id IN ['17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31']
MERGE (s_eng)-[:APPLIES_TO]->(c_eng)
MERGE (s_mob)-[:APPLIES_TO]->(c_mob)
MERGE (s_both)-[:APPLIES_TO]->(c_mob)
MERGE (s_both)-[:APPLIES_TO]->(c_eng)


// Assignment of services into layers
// 1. Mobility: Smart features (Services 1, 16)
MATCH (s:Service), (l:Layer {name: 'Smart features'})
WHERE s.id IN ['1', '16']
MERGE (s)-[:BELONGS_TO_LAYER {context: 'Mobility'}]->(l)

// 2. Mobility: Smart services (Services 15, 2, 3, 4)
MATCH (s:Service)
MATCH (l:Layer {name: 'Smart services'})
WHERE s.id IN ['15', '2', '3', '4']
MERGE (s)-[:BELONGS_TO_LAYER {context: 'Mobility'}]->(l)

// 3. Mobility: Supporting services (Services 5, 14, 6, 7, 8, 9)
MATCH (s:Service)
MATCH (l:Layer {name: 'Supporting services'})
WHERE s.id IN ['5', '14', '6', '7', '8', '9']
MERGE (s)-[:BELONGS_TO_LAYER {context: 'Mobility'}]->(l)

// 4. Mobility: Mobility applications (Services 13, 10)
MATCH (s:Service)
MATCH (l:Layer {name: 'Mobility applications'})
WHERE s.id IN ['13', '10']
MERGE (s)-[:BELONGS_TO_LAYER {context: 'Mobility'}]->(l)

// 5. Mobility: Mobility infrastructure (Services 11, 12)
MATCH (s:Service)
MATCH (l:Layer {name: 'Mobility infrastructure'})
WHERE s.id IN ['11', '12']
MERGE (s)-[:BELONGS_TO_LAYER {context: 'Mobility'}]->(l)

// 1. Energy: Smart features (Services 16, 17)
MATCH (s:Service)
MATCH (l:Layer {name: 'Smart features'})
WHERE s.id IN ['16', '17']
MERGE (s)-[:BELONGS_TO_LAYER {context: 'Energy'}]->(l)

// 2. Energy: Smart services (Services 15, 18)
MATCH (s:Service)
MATCH (l:Layer {name: 'Smart services'})
WHERE s.id IN ['15', '18']
MERGE (s)-[:BELONGS_TO_LAYER {context: 'Energy'}]->(l)

// 3. Energy: Supporting services (Services 19, 30, 31)
MATCH (s:Service)
MATCH (l:Layer {name: 'Supporting services'})
WHERE s.id IN ['19', '30', '31']
MERGE (s)-[:BELONGS_TO_LAYER {context: 'Energy'}]->(l)

// 4. Energy: Energy applications (Services 20, 21, 22, 27, 28, 29, 14)
MATCH (s:Service)
MATCH (l:Layer {name: 'Energy applications'})
WHERE s.id IN ['20', '21', '22', '27', '28', '29', '14']
MERGE (s)-[:BELONGS_TO_LAYER {context: 'Energy'}]->(l)

// 5. Energy: Energy infrastructure (Services 23, 24, 25, 26)
MATCH (s:Service)
MATCH (l:Layer {name: 'Energy infrastructure'})
WHERE s.id IN ['23', '24', '25', '26']
MERGE (s)-[:BELONGS_TO_LAYER {context: 'Energy'}]->(l)


// create relationships representing dependencies

// in context mobility
//Mobility -> Electric mobility, Transport management, Public transport
MATCH (s:Service {name: 'Mobility'}), (t:Service {name: 'Electric mobility'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);
MATCH (s:Service {name: 'Mobility'}), (t:Service {name: 'Transport management'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);
MATCH (s:Service {name: 'Mobility'}), (t:Service {name: 'Public transport'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);

//Energy -> Smart grid
MATCH (s:Service {name: 'Energy'}), (t:Service {name: 'Smart grid'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);

//Electric mobility -> Driving control, Smart charging
MATCH (s:Service {name: 'Electric mobility'}), (t:Service {name: 'Driving control'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);
MATCH (s:Service {name: 'Electric mobility'}), (t:Service {name: 'Smart charging'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);

//Smart grid -> Energy monitoring, Vehicle usage optimization
MATCH (s:Service {name: 'Smart grid'}), (t:Service {name: 'Energy monitoring'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);
MATCH (s:Service {name: 'Smart grid'}), (t:Service {name: 'Vehicle usage optimization'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);

//Transport management -> Energy monitoring, Vehicle usage optimization, Route optimization, Traffic monitoring
MATCH (s:Service {name: 'Transport management'}), (t:Service {name: 'Energy monitoring'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);
MATCH (s:Service {name: 'Transport management'}), (t:Service {name: 'Vehicle usage optimization'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);
MATCH (s:Service {name: 'Transport management'}), (t:Service {name: 'Route optimization'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);
MATCH (s:Service {name: 'Transport management'}), (t:Service {name: 'Traffic monitoring'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);

//Driving control -> Battery monitoring, Regenerative breaking
MATCH (s:Service {name: 'Driving control'}), (t:Service {name: 'Battery monitoring'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);
MATCH (s:Service {name: 'Driving control'}), (t:Service {name: 'Regenerative breaking'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);

//Energy monitoring -> Battery monitoring
MATCH (s:Service {name: 'Energy monitoring'}), (t:Service {name: 'Battery monitoring'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);

//Smart charging -> Battery monitoring
MATCH (s:Service {name: 'Smart charging'}), (t:Service {name: 'Battery monitoring'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);


//Vehicle usage optimization -> Battery monitoring, Regenerative breaking
MATCH (s:Service {name: 'Vehicle usage optimization'}), (t:Service {name: 'Battery monitoring'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);
MATCH (s:Service {name: 'Vehicle usage optimization'}), (t:Service {name: 'Regenerative breaking'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);

//Battery monitoring -> Vehicle, Charging device
MATCH (s:Service {name: 'Battery monitoring'}), (t:Service {name: 'Vehicle'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);
MATCH (s:Service {name: 'Battery monitoring'}), (t:Service {name: 'Charging device'}) CREATE (s)-[:DEPENDS_ON {context: 'Mobility', type: ''}]->(t);

// in context energy
//Energy -> Smart grid
MATCH (s:Service {name: 'Energy'}), (t:Service {name: 'Smart grid'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Urban planning -> Smart buildings
MATCH (s:Service {name: 'Urban planning'}), (t:Service {name: 'Smart buildings'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Smart grid -> Energy 2 grid, Smart grid maintenance, Smart grid monitoring
MATCH (s:Service {name: 'Smart grid'}), (t:Service {name: 'Energy 2 grid'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);
MATCH (s:Service {name: 'Smart grid'}), (t:Service {name: 'Smart grid maintenance'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);
MATCH (s:Service {name: 'Smart grid'}), (t:Service {name: 'Smart grid monitoring'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Smart buildings -> Energy
MATCH (s:Service {name: 'Smart buildings'}), (t:Service {name: 'Energy'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Energy 2 grid -> Communication with the grid
MATCH (s:Service {name: 'Energy 2 grid'}), (t:Service {name: 'Communication with the grid'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Smart grid maintenance -> Optimization of energy distribution, Prediction of energy consumption, Control energy distribution, Energy data analysis software
MATCH (s:Service {name: 'Smart grid maintenance'}), (t:Service {name: 'Optimization of energy distribution'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);
MATCH (s:Service {name: 'Smart grid maintenance'}), (t:Service {name: 'Prediction of energy consumption'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);
MATCH (s:Service {name: 'Smart grid maintenance'}), (t:Service {name: 'Control energy distribution'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);
MATCH (s:Service {name: 'Smart grid maintenance'}), (t:Service {name: 'Energy data analysis software'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Smart grid monitoring -> Energy data collecting, Energy monitoring
MATCH (s:Service {name: 'Smart grid monitoring'}), (t:Service {name: 'Energy data collecting'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);
MATCH (s:Service {name: 'Smart grid monitoring'}), (t:Service {name: 'Energy monitoring'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Communication with the grid -> DRS
MATCH (s:Service {name: 'Communication with the grid'}), (t:Service {name: 'DRS'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Optimization of energy distribution -> DRS
MATCH (s:Service {name: 'Optimization of energy distribution'}), (t:Service {name: 'DRS'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Prediction of energy consumption -> DRS
MATCH (s:Service {name: 'Prediction of energy consumption'}), (t:Service {name: 'DRS'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Control energy distribution -> DRS
MATCH (s:Service {name: 'Control energy distribution'}), (t:Service {name: 'DRS'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Energy data analysis software -> Data concentrator
MATCH (s:Service {name: 'Energy data analysis software'}), (t:Service {name: 'Data concentrator'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Energy data collecting -> Data concentrator, Data collector
MATCH (s:Service {name: 'Energy data collecting'}), (t:Service {name: 'Data concentrator'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);
MATCH (s:Service {name: 'Energy data collecting'}), (t:Service {name: 'Data collector'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);

//Energy monitoring -> Smart meter
MATCH (s:Service {name: 'Energy monitoring'}), (t:Service {name: 'Smart meter'}) CREATE (s)-[:DEPENDS_ON {context: 'Energy', type: ''}]->(t);


// create package in context 'Mobility'

CREATE (p:ServicePackage {name: 'Vehicle control', id: '1'})
MATCH (a {name: 'Vehicle', id: '11', description: ''})
MATCH (b {name: 'Battery monitoring', id: '13', description: ''})
MATCH (d {name: 'Driving control', id: '5', description: ''})
MATCH (c {name: 'Vehicle control', id: '1'})
CREATE (a)-[:BELONGS_TO_PACKAGE {context: 'Mobility'}]->(c)
CREATE (b)-[:BELONGS_TO_PACKAGE {context: 'Mobility'}]->(c)
CREATE (d)-[:BELONGS_TO_PACKAGE {context: 'Mobility'}]->(c)


MATCH (c {name: 'Vehicle control', id: '1'})
MATCH (cMob {name: 'Mobility', description: ''})
CREATE (a)-[:APPLIES_TO]->(c)


// create category in context 'Mobility'

CREATE (p:ServiceCategory {name: 'EnergyOptimization', id: '1'})

MATCH (a {name: 'Smart charging', id: '6', description: ''})
MATCH (b {name: 'Energy monitoring', id: '14', description: ''})
MATCH (d {name: 'Vehicle usage optimization', id: '7', description: ''})
MATCH (c {name: 'EnergyOptimization', id: '1'})
CREATE (a)-[:BELONGS_TO_CATEGORY {context: 'Mobility'}]->(c)
CREATE (b)-[:BELONGS_TO_CATEGORY {context: 'Mobility'}]->(c)
CREATE (d)-[:BELONGS_TO_CATEGORY {context: 'Mobility'}]->(c)

MATCH (c {name: 'EnergyOptimization', id: '1'})
MATCH (cMob {name: 'Mobility', description: ''})
CREATE (a)-[:APPLIES_TO]->(c)


// create stakeholder 'Citizen' that affects both contexts

CREATE (st:Stakeholder {name: 'Citizen', type: 'Individual'})
MATCH (a {name: 'Citizen', type: 'Individual'})
MATCH (b {name: 'Mobility', description: ''})
MATCH (c {name: 'Energy', description: ''})
CREATE (a)-[:AFFECTS_CONTEXT {context: 'Mobility', role: 'End User'}]->(b)
CREATE (a)-[:AFFECTS_CONTEXT {context: 'Energy', role: 'Beneficiary'}]->(c);


// Demonstration of the Stakeholder-Service relationship: Citizen uses public transport

MATCH (a {name: 'Citizen', type: 'Individual'})
MATCH (b {name: 'Public transport', id: '4', description: ''}
CREATE (a)-[:USES {context: 'Mobility'}]->(b)


