<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:neo4j="http://www.liquibase.org/xml/ns/dbchangelog-ext"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

    <changeSet id="WAR-3223_vendor_star_access:1" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: 'b2850464-1612-4f3b-a49e-118e3590b0cb'})
            MERGE (increment:IncrementId {nodeName: 'Profile'})
                ON CREATE SET increment.id = 2
                ON MATCH SET increment.id = increment.id + 1
            CREATE (profile:Profile {
                profileId: (increment.id),
                profileType: 'MoneyhubProfile',
                profileName: identity.name,
                brand: identity.defaultBrand,
                fullCatalogAccess: true,
                roles: ['accounting'],
                uuid: apoc.create.uuid(),
                createdAt: datetime(),
                lastModifiedAt: datetime(),
                createdBy: 'database/WAR-3223_vendor_star_access:1',
                lastModifiedBy: 'database/WAR-3223_vendor_star_access:1'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-3223_vendor_star_access:2" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: 'ab10276c-f851-4080-bb39-2be188013f9a'})
            MERGE (increment:IncrementId {nodeName: 'Profile'})
                ON CREATE SET increment.id = 2
                ON MATCH SET increment.id = increment.id + 1
            CREATE (profile:Profile {
                profileId: (increment.id),
                profileType: 'MoneyhubProfile',
                profileName: identity.name,
                brand: identity.defaultBrand,
                fullCatalogAccess: true,
                roles: ['accounting'],
                uuid: apoc.create.uuid(),
                createdAt: datetime(),
                lastModifiedAt: datetime(),
                createdBy: 'database/WAR-3223_vendor_star_access:2',
                lastModifiedBy: 'database/WAR-3223_vendor_star_access:2'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-3223_vendor_star_access:3" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: 'eee475c1-8462-41da-9b3f-ccb7cfc7c227'})
            MERGE (increment:IncrementId {nodeName: 'Profile'})
                ON CREATE SET increment.id = 2
                ON MATCH SET increment.id = increment.id + 1
            CREATE (profile:Profile {
                profileId: (increment.id),
                profileType: 'MoneyhubProfile',
                profileName: identity.name,
                brand: identity.defaultBrand,
                fullCatalogAccess: true,
                roles: ['accounting'],
                uuid: apoc.create.uuid(),
                createdAt: datetime(),
                lastModifiedAt: datetime(),
                createdBy: 'database/WAR-3223_vendor_star_access:3',
                lastModifiedBy: 'database/WAR-3223_vendor_star_access:3'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-3223_vendor_star_access:4" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: '12791417-bdf0-4bb6-bc9a-c8c7c4e1af85'})
            MERGE (increment:IncrementId {nodeName: 'Profile'})
                ON CREATE SET increment.id = 2
                ON MATCH SET increment.id = increment.id + 1
            CREATE (profile:Profile {
                profileId: (increment.id),
                profileType: 'MoneyhubProfile',
                profileName: identity.name,
                brand: identity.defaultBrand,
                fullCatalogAccess: true,
                roles: ['accounting'],
                uuid: apoc.create.uuid(),
                createdAt: datetime(),
                lastModifiedAt: datetime(),
                createdBy: 'database/WAR-3223_vendor_star_access:4',
                lastModifiedBy: 'database/WAR-3223_vendor_star_access:4'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-3223_vendor_star_access:5" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: '8d427eb2-a6eb-43b9-960f-d573e23ba892'})
                -[:HAS_PROFILE]->(profile:Profile {profileType: 'MoneyhubProfile'}),
                (vendor:Vendor {id: '*'})
            SET profile.fullCatalogAccess = true
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            SET profile.lastModifiedAt = datetime(),
                profile.lastModifiedBy = 'database/WAR-3223_vendor_star_access:5';
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-3223_vendor_star_access:6" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: '88009b2d-09da-45a9-94b6-3e05d261a903'})
                -[:HAS_PROFILE]->(profile:Profile {profileType: 'MoneyhubProfile'}),
                (vendor:Vendor {id: '*'})
            SET profile.fullCatalogAccess = true
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            SET profile.lastModifiedAt = datetime(),
                profile.lastModifiedBy = 'database/WAR-3223_vendor_star_access:6';
            ]]>
        </neo4j:cypher>
    </changeSet>

</databaseChangeLog>
