<?php

/**
 * @file
 * Install functions for the Simple Reservation.
 */

/**
 * Implements of hook_schema().
 */
function simplereservation_schema() {
  $schema['simplereservation_reservation'] = array(
    'description' => '{simplereservation_reservation} holds all reservations done',
    'fields' => array(
      'rid' => array(
        'description' => 'Reservation primary ID',
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'item_id' => array(
        'description' => 'Reservation item ID',
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'uid' => array(
        'description' => 'UID of the user for who the item reserved',
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'for_uid' => array(
        'description' => 'ID of the user for whom the item was reserved for',
        'type' => 'int',
        'not null' => FALSE,
        'unsigned' => TRUE,
      ),
      'begin' => array(
        'description' => 'Time, when the reservation starts',
        'type' => 'int',
        'default' => 0,
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'ending' => array(
        'description' => 'Time, when the reservation ends',
        'type' => 'int',
        'default' => 0,
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'rcomment' => array(
        'description' => 'Text comment that accompanies the reservation',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'whd' => array(
        'description' => 'Whole day reservations',
        'type' => 'int',
        'default' => 1,
        'not null' => FALSE,
        'unsigned' => TRUE,
      ),
    ),
    'primary key' => array('rid'),
    'indexes' => array(
      'rid' => array('rid'),
      'uid' => array('uid'),
    ),
  );

  $schema['simplereservation_item'] = array(
    'description' => '{simplereservation_item} holds all items which can be reserved',
    'fields' => array(
      'iid' => array(
        'description' => 'Item ID',
        'type' => 'serial',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'name' => array(
        'description' => 'Name of the item',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'Description of the item',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'comment' => array(
        'description' => 'Comment of the item',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'status' => array(
        'description' => 'Status of the item (e.g. availability)',
        'type' => 'int',
        'default' => 1,
        'not null' => FALSE,
        'unsigned' => TRUE,
      ),
    ),
    'primary key' => array('iid'),
    'indexes' => array(
      'iid' => array('iid'),
    ),
  );

  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function simplereservation_uninstall() {
  variable_del('simplereservation_max_weeks');
  variable_del('simplereservation_max_reservations');
}
