<?php

function romania_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' => 642,
      'country_name' => 'Romania',
      'country_iso_code_2' => 'RO',
      'country_iso_code_3' => 'ROU',
      'version' => 2,
    ))
    ->execute();

  // VALUES = %d for ID, Parent Country ID, Zone Abbreviation, Zone Name
  $zones = array(
    array(642, 'AB', 'Alba'),
    array(642, 'AR', 'Arad'),
    array(642, 'AG', 'Arges'),
    array(642, 'BC', 'Bacau'),
    array(642, 'BH', 'Bihor'),
    array(642, 'BN', 'Bistrita-Nasaud'),
    array(642, 'BT', 'Botosani'),
    array(642, 'BV', 'Brasov'),
    array(642, 'BR', 'Braila'),
    array(642, 'B',  'Bucuresti'),
    array(642, 'BZ', 'Buzau'),
    array(642, 'CS', 'Caras-Severin'),
    array(642, 'CL', 'Calarasi'),
    array(642, 'CJ', 'Cluj'),
    array(642, 'CT', 'Constanta'),
    array(642, 'CV', 'Covasna'),
    array(642, 'DB', 'Dimbovita'),
    array(642, 'DJ', 'Dolj'),
    array(642, 'GL', 'Galati'),
    array(642, 'GR', 'Giurgiu'),
    array(642, 'GJ', 'Gorj'),
    array(642, 'HR', 'Harghita'),
    array(642, 'HD', 'Hunedoara'),
    array(642, 'IL', 'Ialomita'),
    array(642, 'IS', 'Iasi'),
    array(642, 'IF', 'Ilfov'),
    array(642, 'MM', 'Maramures'),
    array(642, 'MH', 'Mehedinti'),
    array(642, 'MS', 'Mures'),
    array(642, 'NT', 'Neamt'),
    array(642, 'OT', 'Olt'),
    array(642, 'PH', 'Prahova'),
    array(642, 'SM', 'Satu-Mare'),
    array(642, 'SJ', 'Salaj'),
    array(642, 'SB', 'Sibiu'),
    array(642, 'SV', 'Suceava'),
    array(642, 'TR', 'Teleorman'),
    array(642, 'TM', 'Timis'),
    array(642, 'TL', 'Tulcea'),
    array(642, 'VS', 'Vaslui'),
    array(642, 'VL', 'Valcea'),
    array(642, 'VN', 'Vrancea'),
  );

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

function romania_update($version) {
  switch ($version) {
    case 2:
      // Correct ISO-3166-1 country name
      db_update('uc_countries')
        ->fields(array('country_iso_code_3' => 'ROU'))
        ->condition('country_id', 642)
        ->execute();

      break;
  }
}
