<?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-3527_vendor_star_access:1" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (:Identity {id: '58ebfa4f-ddec-45b1-ac36-f20a68e6aaac'})
                -[:HAS_PROFILE]->(profile:Profile {profileType: 'MoneyhubProfile'})
                -[deleted_has_access_to:DELETED_HAS_ACCESS_TO]->(vendor:Vendor {id: '*'})
            DELETE deleted_has_access_to
            WITH profile, vendor
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            SET profile.lastModifiedAt = datetime(),
                profile.lastModifiedBy = 'database/WAR-3527_vendor_star_access:1';
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-3527_vendor_star_access:2" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: '5b65ad83-050f-4929-b486-b97a1c566a33'})
            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-3527_vendor_star_access:2',
                lastModifiedBy: 'database/WAR-3527_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-3527_vendor_star_access:3" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: 'a3e2b63c-4628-4c16-995c-7492b32e82f1'})
            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-3527_vendor_star_access:3',
                lastModifiedBy: 'database/WAR-3527_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-3527_vendor_star_access:4" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: '323a95bb-d066-4936-a202-f6660b42af0f'})
            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-3527_vendor_star_access:4',
                lastModifiedBy: 'database/WAR-3527_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-3527_vendor_star_access:5" author="menger">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {id: '3c8edd70-6968-4c5e-8f94-67b3808a82bd'})
            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-3527_vendor_star_access:5',
                lastModifiedBy: 'database/WAR-3527_vendor_star_access:5'
            })
            MERGE (identity)-[:HAS_PROFILE]->(profile)
            WITH profile
            MATCH (vendor:Vendor {id: '*'})
            MERGE (profile)-[:HAS_ACCESS_TO]->(vendor)
            ]]>
        </neo4j:cypher>
    </changeSet>

</databaseChangeLog>
