<?php
/**
 * @file
 *   Creates the table with mail, count of emails sent and tid fields.
 */

/**
 * Implements hook_schema().
 */
function mandrill_simplenews_report_schema() {
  $schema['mandrill_simplenews_report_newsletter_report'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'report_id' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null'=> TRUE,
      ),
      'tid' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'created' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array('id'),
    'mysql_engine' => 'MyISAM',
  );

  $schema['mandrill_simplenews_report_newsletter_sent'] = array(
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'sent_timestamp' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'sent_to_mail' => array(
        'type' => 'varchar',
        'length' => 254,
        'not null'=> TRUE,
      ),
      'from_mail' => array(
        'type' => 'varchar',
        'length' => 254,
        'not null' => TRUE,
      ),
      'subject' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'tid' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'open_count' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'click_count' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array('id'),
    'indexes' => array(
      'sent_timestamp' => array('sent_timestamp'),
      'sent_to_mail' => array('sent_to_mail'),
      'from_mail' => array('from_mail'),
    ),
    'mysql_engine' => 'MyISAM',
  );

  $schema['mandrill_simplenews_report_subscription_extra'] = array(
    'fields' => array(
      'snid' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'tid' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'last_interaction' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
    ),
    'indexes' => array(
      'snid' => array('snid'),
      'tid' => array('tid'),
    ),
  );
  return $schema;
}
