<?xml version="1.0" encoding="UTF-8"?>
<changelog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.liquigraph.org/schema/1.0/liquigraph.xsd">
    <changeset id="DOC-425-setup-account-access:1" author="j0shua" run-on-change="true">
        <query>
            <![CDATA[
                MATCH (i:Identity {email: "akoshkin@theorchard.com"})-[:HAS_PROFILE]
                ->(p:Profile {profileType: "DocumentsProfile"})-[hat:HAS_ACCESS_TO]->(v:Vendor {id: "*"})
                SET
                    hat.dateDeleted = localdatetime(),
                    hat.updatedOn = localdatetime(),
                    hat.updatedBy = 'database/DOC-425-setup-account-access'
                WITH hat
                    CALL apoc.refactor.setType(hat, 'DELETED_HAS_ACCESS_TO')
                    YIELD input, output
                    RETURN input, output
            ]]>
        </query>
    </changeset>

    <changeset id="DOC-425-setup-account-access:2" author="j0shua" run-on-change="true">
        <query>
            <![CDATA[
                // create a DocumentsProfile for kuhuk
                MERGE (inc:IncrementId {nodeName: 'Profile'})
                    ON CREATE SET inc.id = 2
                    ON MATCH SET inc.id = inc.id + 1


                WITH inc

                MATCH (i:Identity {email: "kgoyal@theorchard.com"})
                MERGE (i)-[hp:HAS_PROFILE]->(p:Profile { profileType: 'DocumentsProfile' })
                ON CREATE SET
                    p.createdAt = datetime(),
                    p.uuid = apoc.create.uuid(),
                    p.profileId = inc.id - 1,
                    p.profileName = i.name,
                    p.fullCatalogAccess = false,
                    p.roles = ['payee_management']
                SET
                    p.updatedBy = 'database/DOC-425-setup-account-access',
                    p.updatedOn = datetime(),

                    hp.createdAt = datetime(),
                    hp.updatedBy = 'database/DOC-425-setup-account-access',
                    hp.updatedOn = datetime()

            ]]>
        </query>
    </changeset>

    <changeset id="DOC-425-setup-account-access:3" author="j0shua" run-on-change="true">
        <query>
            <![CDATA[
                // create a DocumentsProfile for Oliver
                MERGE (inc:IncrementId {nodeName: 'Profile'})
                    ON CREATE SET inc.id = 2
                    ON MATCH SET inc.id = inc.id + 1


                WITH inc

                MATCH (i:Identity {email: "owright@theorchard.com"})
                MERGE (i)-[hp:HAS_PROFILE]->(p:Profile { profileType: 'DocumentsProfile' })
                ON CREATE SET
                    p.createdAt = datetime(),
                    p.uuid = apoc.create.uuid(),
                    p.profileId = inc.id - 1,
                    p.profileName = i.name,
                    p.fullCatalogAccess = false,
                    p.roles = ['payee_management']
                SET
                    p.updatedBy = 'database/DOC-425-setup-account-access',
                    p.updatedOn = datetime(),

                    hp.createdAt = datetime(),
                    hp.updatedBy = 'database/DOC-425-setup-account-access',
                    hp.updatedOn = datetime()
            ]]>
        </query>
    </changeset>

    <changeset id="DOC-425-setup-account-access:4" author="j0shua" run-on-change="true">
        <query>
            <![CDATA[
                WITH [
                    {
                        email: "akoshkin@theorchard.com",
                        vendorIds: [35968, 35970, 35971, 35972, 35974, 35975, 35977, 35976, 35978, 35979, 35980, 35981]
                    },
                    {
                        email: "kgoyal@theorchard.com",
                        vendorIds: [35968, 35970, 35971, 35972, 35974, 35975, 35977, 35976, 35978, 35979, 35980, 35981]
                    },
                    {
                        email: "owright@theorchard.com",
                        vendorIds: [35968, 35970, 35971, 35972, 35974, 35975, 35977, 35976, 35978, 35979, 35980, 35981]
                    },
                    {
                        email: "rfediakov@theorchard.com",
                        vendorIds: [35968, 35970, 35971, 35972, 35974, 35975, 35977, 35976, 35978, 35979, 35980, 35981]
                    },
                    {
                        email: "jgoldsmith@theorchard.com",
                        vendorIds: [35968, 35970, 35971, 35972, 35974, 35975, 35977, 35976, 35978, 35979, 35980, 35981]
                    },
                    {
                        email: "ratoui@theorchard.com",
                        vendorIds: [35968, 35970, 35971, 35972, 35974, 35975, 35977, 35976, 35978, 35979, 35980, 35981]
                    }
                ] as users
                UNWIND range(0, size(users) - 1) AS i
                WITH i, users[i].email as email, users[i].vendorIds as vendorIds

                // attach their profile to the test accounts
                MATCH (identity:Identity {email: email})-[:HAS_PROFILE]
                    ->(p:Profile { profileType: 'DocumentsProfile' })

                UNWIND vendorIds as vendorId
                MATCH (v:Vendor { id: vendorId })
                MERGE (p)-[hat:HAS_ACCESS_TO]->(v)
                SET
                    hat.createdAt = datetime(),
                    hat.updatedOn = datetime(),
                    hat.updatedBy = 'database/DOC-425-setup-account-access'
            ]]>
        </query>
    </changeset>
</changelog>
