package com.ffii.fpsms.py

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class PyJobOrderListMapperTest {

  private val stockUom = "1包X2磅"

  @Test
  fun looksLikePackagingUom_recognizes_standard_pack_strings() {
    assertTrue(PyJobOrderListMapper.looksLikePackagingUom("1包X2磅"))
    assertTrue(PyJobOrderListMapper.looksLikePackagingUom("2磅/包"))
    assertTrue(PyJobOrderListMapper.looksLikePackagingUom("1KG"))
    assertTrue(PyJobOrderListMapper.looksLikePackagingUom("0.9L/包"))
    assertTrue(PyJobOrderListMapper.looksLikePackagingUom("900ml包"))
    assertTrue(PyJobOrderListMapper.looksLikePackagingUom("10個/包"))
    assertTrue(PyJobOrderListMapper.looksLikePackagingUom("1包x800毫升"))
  }

  @Test
  fun looksLikePackagingUom_rejects_usage_and_grade_notes() {
    assertFalse(PyJobOrderListMapper.looksLikePackagingUom("菠菜用"))
    assertFalse(PyJobOrderListMapper.looksLikePackagingUom("熟"))
    assertFalse(PyJobOrderListMapper.looksLikePackagingUom("樽裝用"))
    assertFalse(PyJobOrderListMapper.looksLikePackagingUom("餐廳用"))
    assertFalse(PyJobOrderListMapper.looksLikePackagingUom("無糖"))
    assertFalse(PyJobOrderListMapper.looksLikePackagingUom("P+4"))
    assertFalse(PyJobOrderListMapper.looksLikePackagingUom("P+10"))
  }

  @Test
  fun buildDisplayItemName_appends_uom_when_parens_are_not_packaging() {
    assertEquals(
      "芝士醬(菠菜用)($stockUom)",
      PyJobOrderListMapper.buildDisplayItemName("芝士醬(菠菜用)", stockUom),
    )
    assertEquals(
      "(熟)大冬菇($stockUom)",
      PyJobOrderListMapper.buildDisplayItemName("(熟)大冬菇", stockUom),
    )
    assertEquals(
      "鮮檸檬汁(P+4)($stockUom)",
      PyJobOrderListMapper.buildDisplayItemName("鮮檸檬汁(P+4)", stockUom),
    )
  }

  @Test
  fun buildDisplayItemName_skips_append_when_packaging_uom_already_in_name() {
    assertEquals(
      "咖哩汁(1包X2磅)",
      PyJobOrderListMapper.buildDisplayItemName("咖哩汁(1包X2磅)", stockUom),
    )
    assertEquals(
      "(樽裝用)凍咖啡底P+10(0.9L/包)",
      PyJobOrderListMapper.buildDisplayItemName("(樽裝用)凍咖啡底P+10(0.9L/包)", stockUom),
    )
    assertEquals(
      "酸辣湯(2磅/包)",
      PyJobOrderListMapper.buildDisplayItemName("酸辣湯(2磅/包)", "2磅/包"),
    )
  }

  @Test
  fun buildDisplayItemNameForLaser_omits_appended_uom_for_PP1175() {
    assertEquals(
      "鮮檸檬汁(P+4)",
      PyJobOrderListMapper.buildDisplayItemNameForLaser("鮮檸檬汁(P+4)", stockUom, "PP1175"),
    )
    assertEquals(
      "咖哩汁(1包X2磅)",
      PyJobOrderListMapper.buildDisplayItemNameForLaser("咖哩汁(1包X2磅)", stockUom, "PP1080"),
    )
  }
}
