<?php

/**
 * Implements hook_install() using the name of the country as the base of
 * the function name.
 */
function brazil_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' => 76,
      'country_name' => 'Brazil',
      'country_iso_code_2' => 'BR',
      'country_iso_code_3' => 'BRA',
      'version' => 1,
    ))
    ->execute();

  // Make the entries in the zones table.
  $zones = array(
    array(76, 'AC', 'Acre'),
    array(76, 'AL', 'Alagoas'),
    array(76, 'AP', 'Amapá'),
    array(76, 'AM', 'Amazonas'),
    array(76, 'BA', 'Bahia'),
    array(76, 'CE', 'Ceará'),
    array(76, 'DF', 'Distrito Federal'),
    array(76, 'ES', 'Espírito Santo'),
    array(76, 'GO', 'Goiás'),
    array(76, 'MA', 'Maranhão'),
    array(76, 'MT', 'Mato Grosso'),
    array(76, 'MS', 'Mato Grosso do Sul'),
    array(76, 'MG', 'Minas Gerais'),
    array(76, 'PA', 'Pará'),
    array(76, 'PB', 'Paraíba'),
    array(76, 'PR', 'Paraná'),
    array(76, 'PE', 'Pernambuco'),
    array(76, 'PI', 'Piauí'),
    array(76, 'RJ', 'Rio de Janeiro'),
    array(76, 'RN', 'Rio Grande do Norte'),
    array(76, 'RS', 'Rio Grande do Sul'),
    array(76, 'RO', 'Rondônia'),
    array(76, 'RR', 'Roraima'),
    array(76, 'SC', 'Santa Catarina'),
    array(76, 'SP', 'São Paulo'),
    array(76, 'SE', 'Sergipe'),
    array(76, 'TO', 'Tocantins'),
  );

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