<?php

/**
 * @file
 * Install, update and uninstall functions for the Webform access module.
 */

use Drupal\Core\Entity\EntityTypeInterface;

/**
 * Implements hook_schema().
 */
function webform_access_schema() {
  $schema['webform_access_group_user'] = [
    'description' => 'Stores users associated with a webform access group.',
    'fields' => [
      'group_id' => [
        'description' => 'The webform access group id.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ],
      'uid' => [
        'description' => 'The user id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'indexes' => [
      'indexing' => ['group_id', 'uid'],
    ],
    'primary key' => ['group_id', 'uid'],
  ];

  $schema['webform_access_group_entity'] = [
    'description' => 'Stores users associated with a webform access group.',
    'fields' => [
      'group_id' => [
        'description' => 'The webform access group id.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ],
      'entity_type' => [
        'description' => 'The source entity type.',
        'type' => 'varchar',
        'length' => EntityTypeInterface::ID_MAX_LENGTH,
        'not null' => TRUE,
      ],
      'entity_id' => [
        'description' => 'The source entity id.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'field_name' => [
        'description' => 'The webform field name.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ],
      'webform_id' => [
        'description' => 'The webform id.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ],
    ],
    'indexes' => [
      'source_entity' => ['entity_type', 'entity_id', 'field_name', 'webform_id'],
    ],
    'primary key' => ['group_id', 'webform_id', 'entity_type', 'entity_id', 'field_name'],
  ];

  return $schema;
}
