<?php

/**
 * Implements HOOK_schema().
 */
function diy_product_schema() {
  $schema['diy_product'] = array(
    'description' => 'The base table for external products.',
    'fields' => array(
      'pid' => array(
        'description' => 'Product id.',
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'source' => array(
        'description' => 'Source for this entry (eg affilinet).',
        'type' => 'text',
        'size' => 'small',
        'not null' => FALSE
      ),
      'external_id' => array(
        'description' => 'Reference id for products (eg affilinet id).',
        'type' => 'int',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'shop_nid' => array(
        'description' => 'shop nid.',
        'type' => 'int',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'article_number' => array(
        'description' => 'Article number (external, eg. producer number).',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE
      ),
      'title' => array(
        'description' => 'Product title.',
        'type' => 'text',
        'size' => 'medium',
        'not null' => TRUE
      ),
      'description' => array(
        'description' => 'description.',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE
      ),
      'deeplink' => array(
        'description' => 'Deeplink.',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE
      ),
      'producer' => array(
        'description' => 'Producer.',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE
      ),
      'ean' => array(
        'description' => 'EAN Code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE
      ),
      'price' => array(
        'description' => 'Price.',
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'delivery_costs' => array(
        'description' => 'Delivery costs.',
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'delivery_time' => array(
        'description' => 'Delivery time.',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE
      ),
      'image_url' => array(
        'description' => 'URL to image file.',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE
      ),
      'created' => array(
        'description' => 'Created timestamp.',
        'type' => 'int',
        'not null' => FALSE
      ),
      'updated' => array(
        'description' => 'last change timestamp.',
        'type' => 'int',
        'not null' => FALSE
      ),
    ),
    'primary key' => array('pid'),
  );

  $schema['diy_product_price'] = array(
    'description' => 'The base table for price informations on drupal products.',
    'fields' => array(
      'pid' => array(
        'description' => 'Price id.',
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'status' => array(
        'description' => 'State of this entry (0 = new, 1 = show, 2 = ignore, 3 = disappeared in api).',
        'type' => 'int',
        'size' => 'tiny',
        'not null' => TRUE,
      ),
      'product_nid' => array(
        'description' => 'Product nid.',
        'type' => 'int',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'shop_nid' => array(
        'description' => 'shop nid.',
        'type' => 'int',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'source' => array(
        'description' => 'Source for this entry (eg affilinet).',
        'type' => 'text',
        'size' => 'small',
        'not null' => FALSE
      ),
      'external_id' => array(
        'description' => 'Reference id for products (eg affilinet id).',
        'type' => 'int',
        'size' => 'big',
        'not null' => TRUE,
      ),
      'delivery_time' => array(
        'description' => 'Delivery time.',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE
      ),
      'deeplink' => array(
        'description' => 'Deeplink.',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE
      ),
      'price' => array(
        'description' => 'Price.',
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'delivery_costs' => array(
        'description' => 'Delivery costs.',
        'type' => 'float',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'created' => array(
        'description' => 'Created timestamp.',
        'type' => 'int',
        'not null' => FALSE
      ),
      'updated' => array(
        'description' => 'last change timestamp.',
        'type' => 'int',
        'not null' => FALSE
      ),
    ),
    'primary key' => array('pid'),
  );

  return $schema;
}