<?php

/**
 * Implements hook_install() using the name of the country as the base of
 * the function name.
 */
function uruguay_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' => 858,
      'country_name' => 'Uruguay',
      'country_iso_code_2' => 'UY',
      'country_iso_code_3' => 'URY',
      'version' => 1,
    ))
    ->execute();

  // Make the entries in the zones table.
  $zones = array(
    array(858, 'AR', 'Artigas'),
    array(858, 'CA', 'Canelones'),
    array(858, 'CL', 'Cerro Largo'),
    array(858, 'CO', 'Colonia'),
    array(858, 'DU', 'Durazno'),
    array(858, 'FS', 'Flores'),
    array(858, 'FD', 'Florida'),
    array(858, 'LA', 'Lavalleja'),
    array(858, 'MA', 'Maldonado'),
    array(858, 'MO', 'Montevideo'),
    array(858, 'PA', 'Paysandu'),
    array(858, 'RN', 'Rio Negro'),
    array(858, 'RV', 'Rivera'),
    array(858, 'RO', 'Rocha'),
    array(858, 'SA', 'Salto'),
    array(858, 'SJ', 'San Jose'),
    array(858, 'SO', 'Soriano'),
    array(858, 'TA', 'Tacuarembo'),
    array(858, 'TT', 'Treinta y Tres'),
  );

  $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(
    858,
    "!company\r\n".
    "!first_name !last_name\r\n".
    "!street1\r\n".
    "!street2\r\n".
    "!city !zone_code !postal_code\r\n".
    "!country_name_if"
  );
}
