-- CreateEnum
CREATE TYPE "Capabilities" AS ENUM (
    'movePub',
    'createPub',
    'viewPub',
    'deletePub',
    'updatePubValues',
    'createRelatedPub',
    'createPubWithForm',
    'editPubWithForm',
    'createPubField',
    'archivePubField',
    'editPubField',
    'createPubType',
    'editPubType',
    'deletePubType',
    'runAction',
    'viewStage',
    'createStage',
    'manageStage',
    'deleteStage',
    'addPubMember',
    'removePubMember',
    'addStageMember',
    'removeStageMember',
    'addFormMember',
    'removeFormMember',
    'addCommunityMember',
    'removeCommunityMember',
    'manageMemberGroups',
    'addCommunity',
    'editCommunity',
    'createForm',
    'editForm',
    'archiveForm',
    'createApiToken',
    'revokeApiToken'
);

-- CreateEnum
CREATE TYPE "MembershipType" AS ENUM ('community', 'stage', 'pub', 'form');

-- CreateTable
CREATE TABLE "membership_capabilities" (
    "role" "MemberRole" NOT NULL,
    "type" "MembershipType" NOT NULL,
    "capability" "Capabilities" NOT NULL,

    CONSTRAINT "membership_capabilities_pkey" PRIMARY KEY ("role","type","capability")
);

INSERT INTO "membership_capabilities"
VALUES
    ('contributor'::"MemberRole", 'stage'::"MembershipType", 'movePub'::"Capabilities"),
    ('contributor'::"MemberRole", 'stage'::"MembershipType", 'createPub'::"Capabilities"),
    ('contributor'::"MemberRole", 'stage'::"MembershipType", 'viewPub'::"Capabilities"),
    ('contributor'::"MemberRole", 'stage'::"MembershipType", 'updatePubValues'::"Capabilities"),
    ('contributor'::"MemberRole", 'stage'::"MembershipType", 'createRelatedPub'::"Capabilities"),
    ('contributor'::"MemberRole", 'stage'::"MembershipType", 'editPubWithForm'::"Capabilities"),
    ('contributor'::"MemberRole", 'stage'::"MembershipType", 'runAction'::"Capabilities"),
    ('contributor'::"MemberRole", 'stage'::"MembershipType", 'viewStage'::"Capabilities"),
    ('editor'::"MemberRole", 'stage'::"MembershipType", 'movePub'::"Capabilities"),
    ('editor'::"MemberRole", 'stage'::"MembershipType", 'createPub'::"Capabilities"),
    ('editor'::"MemberRole", 'stage'::"MembershipType", 'viewPub'::"Capabilities"),
    ('editor'::"MemberRole", 'stage'::"MembershipType", 'updatePubValues'::"Capabilities"),
    ('editor'::"MemberRole", 'stage'::"MembershipType", 'createRelatedPub'::"Capabilities"),
    ('editor'::"MemberRole", 'stage'::"MembershipType", 'createPubWithForm'::"Capabilities"),
    ('editor'::"MemberRole", 'stage'::"MembershipType", 'editPubWithForm'::"Capabilities"),
    ('editor'::"MemberRole", 'stage'::"MembershipType", 'runAction'::"Capabilities"),
    ('editor'::"MemberRole", 'stage'::"MembershipType", 'viewStage'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'movePub'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'createPub'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'viewPub'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'deletePub'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'updatePubValues'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'createRelatedPub'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'createPubWithForm'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'editPubWithForm'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'runAction'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'viewStage'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'manageStage'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'addPubMember'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'removePubMember'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'addStageMember'::"Capabilities"),
    ('admin'::"MemberRole", 'stage'::"MembershipType", 'removeStageMember'::"Capabilities"),
    ('contributor'::"MemberRole", 'pub'::"MembershipType", 'viewPub'::"Capabilities"),
    ('contributor'::"MemberRole", 'pub'::"MembershipType", 'updatePubValues'::"Capabilities"),
    ('contributor'::"MemberRole", 'pub'::"MembershipType", 'editPubWithForm'::"Capabilities"),
    ('editor'::"MemberRole", 'pub'::"MembershipType", 'movePub'::"Capabilities"),
    ('editor'::"MemberRole", 'pub'::"MembershipType", 'viewPub'::"Capabilities"),
    ('editor'::"MemberRole", 'pub'::"MembershipType", 'updatePubValues'::"Capabilities"),
    ('editor'::"MemberRole", 'pub'::"MembershipType", 'createRelatedPub'::"Capabilities"),
    ('editor'::"MemberRole", 'pub'::"MembershipType", 'editPubWithForm'::"Capabilities"),
    ('admin'::"MemberRole", 'pub'::"MembershipType", 'movePub'::"Capabilities"),
    ('admin'::"MemberRole", 'pub'::"MembershipType", 'viewPub'::"Capabilities"),
    ('admin'::"MemberRole", 'pub'::"MembershipType", 'deletePub'::"Capabilities"),
    ('admin'::"MemberRole", 'pub'::"MembershipType", 'updatePubValues'::"Capabilities"),
    ('admin'::"MemberRole", 'pub'::"MembershipType", 'createRelatedPub'::"Capabilities"),
    ('admin'::"MemberRole", 'pub'::"MembershipType", 'createPubWithForm'::"Capabilities"),
    ('admin'::"MemberRole", 'pub'::"MembershipType", 'editPubWithForm'::"Capabilities"),
    ('admin'::"MemberRole", 'pub'::"MembershipType", 'runAction'::"Capabilities"),
    ('editor'::"MemberRole", 'community'::"MembershipType", 'movePub'::"Capabilities"),
    ('editor'::"MemberRole", 'community'::"MembershipType", 'createPub'::"Capabilities"),
    ('editor'::"MemberRole", 'community'::"MembershipType", 'viewPub'::"Capabilities"),
    ('editor'::"MemberRole", 'community'::"MembershipType", 'deletePub'::"Capabilities"),
    ('editor'::"MemberRole", 'community'::"MembershipType", 'updatePubValues'::"Capabilities"),
    ('editor'::"MemberRole", 'community'::"MembershipType", 'createRelatedPub'::"Capabilities"),
    ('editor'::"MemberRole", 'community'::"MembershipType", 'createPubWithForm'::"Capabilities"),
    ('editor'::"MemberRole", 'community'::"MembershipType", 'editPubWithForm'::"Capabilities"),
    ('editor'::"MemberRole", 'community'::"MembershipType", 'runAction'::"Capabilities"),
    ('editor'::"MemberRole", 'community'::"MembershipType", 'viewStage'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'movePub'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'createPub'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'viewPub'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'deletePub'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'updatePubValues'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'createRelatedPub'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'createPubWithForm'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'editPubWithForm'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'createPubField'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'archivePubField'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'editPubField'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'createPubType'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'editPubType'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'deletePubType'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'runAction'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'viewStage'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'createStage'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'manageStage'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'deleteStage'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'addPubMember'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'removePubMember'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'addStageMember'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'removeStageMember'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'addFormMember'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'removeFormMember'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'addCommunityMember'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'removeCommunityMember'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'manageMemberGroups'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'addCommunity'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'editCommunity'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'createForm'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'editForm'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'archiveForm'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'createApiToken'::"Capabilities"),
    ('admin'::"MemberRole", 'community'::"MembershipType", 'revokeApiToken'::"Capabilities")
;
