(module main)

(import std.io (print_i32_zero print_u32_zero print_i64_zero print_u64_zero print_f64_zero print_string_zero print_bool_zero print_i32_value print_u32_value print_i64_value print_u64_value print_f64_value print_string_value print_bool_value read_stdin_result read_stdin_option read_stdin_or read_stdin_i32_result read_stdin_i32_option read_stdin_i32_or_zero read_stdin_i32_or read_stdin_u32_result read_stdin_u32_option read_stdin_u32_or_zero read_stdin_u32_or read_stdin_i64_result read_stdin_i64_option read_stdin_i64_or_zero read_stdin_i64_or read_stdin_u64_result read_stdin_u64_option read_stdin_u64_or_zero read_stdin_u64_or read_stdin_f64_result read_stdin_f64_option read_stdin_f64_or_zero read_stdin_f64_or read_stdin_bool_result read_stdin_bool_option read_stdin_bool_or_false read_stdin_bool_or))

(fn imported_print_i32_status () -> i32
  (print_i32_zero 42))

(fn imported_print_i64_status () -> i32
  (print_i64_zero 42i64))

(fn imported_print_u32_status () -> i32
  (print_u32_zero 42u32))

(fn imported_print_u64_status () -> i32
  (print_u64_zero 42u64))

(fn imported_print_f64_status () -> i32
  (print_f64_zero 42.5))

(fn imported_print_string_status () -> i32
  (print_string_zero "slovo"))

(fn imported_print_bool_status () -> i32
  (print_bool_zero true))

(fn imported_print_value_helpers_ok () -> bool
  (if (= (print_u32_value 42u32) 42u32)
    (if (= (print_i64_value 42i64) 42i64)
      (if (= (print_u64_value 42u64) 42u64)
        (if (= (print_f64_value 42.5) 42.5)
          true
          false)
        false)
      false)
    false))

(fn imported_stdin_result_ok () -> bool
  (match (read_stdin_result)
    ((ok payload)
      (= payload ""))
    ((err code)
      false)))

(fn imported_stdin_option_ok () -> bool
  (match (read_stdin_option)
    ((some payload)
      (= payload ""))
    ((none)
      false)))

(fn imported_stdin_text_fallback_ok () -> bool
  (= (read_stdin_or "fallback") ""))

(fn imported_stdin_typed_results_ok () -> bool
  (if (match (read_stdin_i32_result)
    ((ok payload)
      false)
    ((err code)
      true))
    (if (match (read_stdin_u32_result)
      ((ok payload)
        false)
      ((err code)
        true))
      (if (match (read_stdin_i64_result)
        ((ok payload)
          false)
        ((err code)
          true))
        (if (match (read_stdin_u64_result)
          ((ok payload)
            false)
          ((err code)
            true))
          (if (match (read_stdin_f64_result)
            ((ok payload)
              false)
            ((err code)
              true))
            (match (read_stdin_bool_result)
              ((ok payload)
                false)
              ((err code)
                true))
            false)
          false)
        false)
      false)
    false))

(fn imported_stdin_typed_options_ok () -> bool
  (if (match (read_stdin_i32_option)
    ((some payload)
      false)
    ((none)
      true))
    (if (match (read_stdin_u32_option)
      ((some payload)
        false)
      ((none)
        true))
      (if (match (read_stdin_i64_option)
        ((some payload)
          false)
        ((none)
          true))
        (if (match (read_stdin_u64_option)
          ((some payload)
            false)
          ((none)
            true))
          (if (match (read_stdin_f64_option)
            ((some payload)
              false)
            ((none)
              true))
            (match (read_stdin_bool_option)
              ((some payload)
                false)
              ((none)
                true))
            false)
          false)
        false)
      false)
    false))

(fn imported_stdin_bool_fallbacks_ok () -> bool
  (let empty_bool bool (read_stdin_bool_or_false))
  (let fallback_bool bool (read_stdin_bool_or true))
  (if empty_bool
    false
    fallback_bool))

(fn imported_stdin_typed_fallbacks_ok () -> bool
  (if (= (read_stdin_i32_or_zero) 0)
    (if (= (read_stdin_i32_or 7) 7)
      (if (= (read_stdin_u32_or_zero) 0u32)
        (if (= (read_stdin_u32_or 7u32) 7u32)
          (if (= (read_stdin_i64_or_zero) 0i64)
            (if (= (read_stdin_i64_or 9i64) 9i64)
              (if (= (read_stdin_u64_or_zero) 0u64)
                (if (= (read_stdin_u64_or 9u64) 9u64)
                  (if (= (read_stdin_f64_or_zero) 0.0)
                    (if (= (read_stdin_f64_or 1.5) 1.5)
                      (imported_stdin_bool_fallbacks_ok)
                      false)
                    false)
                  false)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

(fn imported_io_status_all () -> i32
  (imported_print_u32_status)
  (imported_print_i64_status)
  (imported_print_u64_status)
  (imported_print_f64_status)
  42)

(fn imported_io_helpers_ok () -> bool
  (if (= (imported_io_status_all) 42)
    (if (imported_print_value_helpers_ok)
      (if (imported_stdin_result_ok)
        (if (imported_stdin_option_ok)
          (if (imported_stdin_text_fallback_ok)
            (if (imported_stdin_typed_results_ok)
              (if (imported_stdin_typed_options_ok)
                (imported_stdin_typed_fallbacks_ok)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

(fn main () -> i32
  (if (imported_io_helpers_ok)
    42
    1))

(test "explicit std io i64 zero facade"
  (= (imported_print_i64_status) 0))

(test "explicit std io u32 zero facade"
  (= (imported_print_u32_status) 0))

(test "explicit std io u64 zero facade"
  (= (imported_print_u64_status) 0))

(test "explicit std io f64 zero facade"
  (= (imported_print_f64_status) 0))

(test "explicit std io value facade"
  (imported_print_value_helpers_ok))

(test "explicit std io stdin result facade"
  (imported_stdin_result_ok))

(test "explicit std io stdin option facade"
  (imported_stdin_option_ok))

(test "explicit std io stdin text fallback facade"
  (imported_stdin_text_fallback_ok))

(test "explicit std io stdin typed result facade"
  (imported_stdin_typed_results_ok))

(test "explicit std io stdin typed option facade"
  (imported_stdin_typed_options_ok))

(test "explicit std io stdin typed fallback facade"
  (imported_stdin_typed_fallbacks_ok))

(test "explicit std io helpers all"
  (= (main) 42))
