<?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-2231_add_vendor_star_access:1" author="epohrebna">
        <neo4j:cypher>
            <![CDATA[
            WITH [
                'javier.gonzalez@sonymusic-pde.com',
                'miguel.martorell@altafonte.com',
                'octavio.vinck@altafonte.com',
                'maria.fernandez@altafonte.com',
                'manuel.pena@altafonte.com',
                'dario.mehrgut@sonymusic-pde.com',
                'cecilia.huerta@altafonte.com',
                'sergio.martin@sonymusic-pde.com',
                'camilo.vega@altafonte.com',
                'patricia.castellanos@altafonte.com',
                'kervin.martinez@altafonte.com',
                'cesar.rodriguez@altafonte.com',
                'alberto.rodriguez@sonymusic-pde.com',
                'daniel.jimenez@sonymusic-pde.com',
                'montse.delasheras@altafonte.com',
                'alex.schiavo@altafonte.com',
                'sandra.ortega@altafonte.com',
                'alejandro.pelaz@altafonte.com',
                'elyssa.garrett@altafonte.com',
                'uriel.vargas@altafonte.com',
                'florencia.saavedra@altafonte.com',
                'ana.biedma@altafonte.com',
                'nuno.serrao@altafonte.com',
                'christiane.silvestre@altafonte.com',
                'ivanna.rucoba@altafonte.com',
                'cristobal.colom@altafonte.com',
                'stefany.navarro@altafonte.com',
                'nathaly.garcia@altafonte.com',
                'nicolas.brozovich@altafonte.com',
                'miguel.lopez@sonymusic-pde.com',
                'javier.arribas@altafonte.com',
                'adrian.gonzalo@sonymusic-pde.com',
                'tomas.crespo@altafonte.com',
                'karmen.ibarra@altafonte.com',
                'antonio.lozano@altafonte.com',
                'giulia.giampietro@altafonte.com',
                'rayane.brum@altafonte.com',
                'reyes.ceron@altafonte.com',
                'jorge.bertran@sonymusic-pde.com',
                'nuria.pinto@altafonte.com',
                'juan.diaz@sonymusic-pde.com',
                'juliana.gomez@altafonte.com',
                'melissa.padilla@altafonte.com',
                'eric.kropp@altafonte.com',
                'felipe.lugo@altafonte.com',
                'nicolas.ichkhanian@altafonte.com',
                'milagros.amorena@altafonte.com',
                'camila.pietrafesa@altafonte.com',
                'gabriela.fernandez@altafonte.com',
                'valentina.rosas@altafonte.com',
                'arancha.bahillo@altafonte.com',
                'camilo.molina@altafonte.com',
                'roman.lopez@altafonte.com',
                'daniela.jimenez@altafonte.com',
                'othon.chaparro@altafonte.com',
                'anabel.almeda@sonymusic-pde.com',
                'jose.fanjul@sonymusic-pde.com',
                'alberto.montoya@sonymusic-pde.com',
                'leonardo.parisi@altafonte.com',
                'pedro.ortiz@altafonte.com',
                'fernanda.perez@altafonte.com',
                'alexis.rabago@altafonte.com',
                'pablo.llanos@altafonte.com',
                'roberto.gimeno@altafonte.com',
                'alberto.villanueva@altafonte.com',
                'tania.rocha@altafonte.com',
                'angela.cadavid@altafonte.com',
                'cesar.hernandez@altafonte.com',
                'mariana.paulino@altafonte.com',
                'regina.demiguel@altafonte.com',
                'alicia.moure@altafonte.com',
                'vicente.soler@altafonte.com',
                'michelly.mury@altafonte.com',
                'alexandre.ribeiro@altafonte.com',
                'monica.brandao@altafonte.com',
                'jorge.sanchez@altafonte.com',
                'alfonso.larriva@altafonte.com',
                'mariadelmar.mosquera@altafonte.com',
                'diego.bravo@altafonte.com',
                'wellington.chagas@altafonte.com',
                'danielle.magalhaes@altafonte.com',
                'paula.franca@altafonte.com',
                'catrina.lang@altafonte.com',
                'jean.perez@altafonte.com',
                'maria.mestre@altafonte.com',
                'katherine.held@altafonte.com',
                'rodrigo.soares@altafonte.com',
                'maria.pascual@altafonte.com',
                'alfredo.perea.ext@altafonte.com',
                'irene.molla@altafonte.com'
            ] AS emails
            UNWIND emails AS email
            MATCH (identity:Identity {email: email})
            WITH collect(identity) AS identities
            WITH identities, size(identities) AS totalRows
            UNWIND range(0, totalRows - 1) AS rowNumber
            WITH totalRows, rowNumber, identities[rowNumber] AS identity
            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 - totalRows + rowNumber + 1,
                profileType: 'MoneyhubProfile',
                profileName: identity.name,
                brand: identity.defaultBrand,
                fullCatalogAccess: true,
                roles: ['accounting'],
                uuid: apoc.create.uuid(),
                createdAt: datetime(),
                lastModifiedAt: datetime(),
                createdBy: 'database/WAR-2231_add_vendor_star_access:1',
                lastModifiedBy: 'database/WAR-2231_add_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-2231_add_vendor_star_access:2" author="epohrebna">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {email: 'adrian.delarosa@sonymusic-pde.com'})-[: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-2231_add_vendor_star_access:2';
            ]]>
        </neo4j:cypher>
    </changeSet>

    <changeSet id="WAR-2231_add_vendor_star_access:3" author="epohrebna">
        <neo4j:cypher>
            <![CDATA[
            MATCH (identity:Identity {email: 'tony.martin@sonymusic-pde.com'})-[: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-2231_add_vendor_star_access:3';
            ]]>
        </neo4j:cypher>
    </changeSet>
</databaseChangeLog>
