<?php

function korea_democratic_peoples_republic_of_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' => 408,
      'country_name' => "Korea, Democratic People's Republic of",
      'country_iso_code_2' => 'KP',
      'country_iso_code_3' => 'PRK',
      'version' => 2,
    ))
    ->execute();

  // Make the entries in the zones table.
  $zones = array(
    array(408, 'KP-01', 'P’yŏngyang'),
    array(408, 'KP-13', 'Nasŏn (Najin-Sŏnbong'),
    array(408, 'KP-02', 'P’yŏngan-namdo'),
    array(408, 'KP-03', 'P’yŏngan-bukto'),
    array(408, 'KP-04', 'Chagang-do'),
    array(408, 'KP-05', 'Hwanghae-namdo'),
    array(408, 'KP-06', 'Hwanghae-bukto'),
    array(408, 'KP-07', 'Kangwŏn-do'),
    array(408, 'KP-08', 'Hamgyŏng-namdo'),
    array(408, 'KP-09', 'Hamgyŏng-bukto'),
    array(408, 'KP-10', 'Yanggang-do'),
  );

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

function korea_democratic_peoples_republic_of_update($version) {
  switch ($version) {
    case 2:
      // Correct ISO-3166-1 country name
      db_update('uc_countries')
        ->fields(array('country_name' => "Korea, Democratic People's Republic of"))
        ->condition('country_id', 408)
        ->execute();

      break;
  }
}
