<?php

function belgium_install() {
  // Make the entry in the country table.
  // VALUES = Country ID, Country Name, 2-digit Code, 3-digit Code, File Version
  db_insert('uc_countries')
    ->fields(array(
      'country_id' => 56,
      'country_name' => 'Belgium',
      'country_iso_code_2' => 'BE',
      'country_iso_code_3' => 'BEL',
      'version' => 3,
    ))
    ->execute();

  // Make the entries in the zones table.
  $zones = array(
    array(56, 'VWV', 'West-Vlaanderen'),
    array(56, 'VOV', 'Oost-Vlaanderen'),
    array(56, 'VAN', 'Antwerpen'),
    array(56, 'VLI', 'Limburg'),
    array(56, 'VBR', 'Vlaams-Brabant'),
    array(56, 'BRU', 'Brussel/Bruxelles'),
    array(56, 'WBW', 'Brabant-Wallon'),
    array(56, 'WLG', 'Liège'),
    array(56, 'WHT', 'Hainaut'),
    array(56, 'WNA', 'Namur'),
    array(56, 'WLX', 'Luxembourg'),
  );

  $query = db_insert('uc_zones')->fields(array('zone_country_id', 'zone_code', 'zone_name'));
  foreach ($zones as $zone) {
    $query->values($zone);
  }
  $query->execute();

  // Set address format
  uc_set_address_format(
    56,
    "!company\r\n".
    "!first_name !last_name\r\n".
    "!street1\r\n".
    "!street2\r\n".
    "!postal_code !city\r\n".
    "!country_name_if"
  );
}

function belgium_update($version) {
  switch ($version) {
    case '2':
      // Update existing zone codes and names.
      db_update('uc_zones')
        ->fields(array('zone_code' => 'VWV'))
        ->condition('zone_code', 'WV')
        ->condition('zone_country_id', 56)
        ->execute();
      db_update('uc_zones')
        ->fields(array('zone_code' => 'VOV'))
        ->condition('zone_code', 'OV')
        ->condition('zone_country_id', 56)
        ->execute();
      db_update('uc_zones')
        ->fields(array('zone_code' => 'VAN'))
        ->condition('zone_code', 'AN')
        ->condition('zone_country_id', 56)
        ->execute();
      db_update('uc_zones')
        ->fields(array('zone_code' => 'VLI'))
        ->condition('zone_code', 'LG')
        ->condition('zone_country_id', 56)
        ->execute();
      db_update('uc_zones')
        ->fields(array('zone_code' => 'VBR'))
        ->condition('zone_code', 'VB')
        ->condition('zone_country_id', 56)
        ->execute();
      db_update('uc_zones')
        ->fields(array('zone_name' => 'Brabant-Wallon', 'zone_code' => 'WBR'))
        ->condition('zone_code', 'BW')
        ->condition('zone_country_id', 56)
        ->execute();
      db_update('uc_zones')
        ->fields(array('zone_name' => 'Liège', 'zone_code' => 'WLG'))
        ->condition('zone_code', 'LB')
        ->condition('zone_country_id', 56)
        ->execute();
      db_update('uc_zones')
        ->fields(array('zone_name' => 'Hainaut', 'zone_code' => 'WHT'))
        ->condition('zone_code', 'HT')
        ->condition('zone_country_id', 56)
        ->execute();
      db_update('uc_zones')
        ->fields(array('zone_name' => 'Namur', 'zone_code' => 'WNA'))
        ->condition('zone_code', 'NM')
        ->condition('zone_country_id', 56)
        ->execute();
      db_update('uc_zones')
        ->fields(array('zone_name' => 'Luxembourg', 'zone_code' => 'WLX'))
        ->condition('zone_code', 'LU')
        ->condition('zone_country_id', 56)
        ->execute();

      // Insert Brussels.
      db_insert('uc_zones')
        ->fields(array(
            'zone_country_id' => 56,
            'zone_code' => 'BRU',
            'zone_name' => 'Brussel/Bruxelles',
          ))
        ->execute();

      break;
  }
}
