(module main)

(import std.process (argc arg arg_result arg_option has_arg arg_or arg_or_empty arg_i32_result arg_i32_option arg_i32_or_zero arg_i32_or arg_u32_result arg_u32_option arg_u32_or_zero arg_u32_or arg_i64_result arg_i64_option arg_i64_or_zero arg_i64_or arg_u64_result arg_u64_option arg_u64_or_zero arg_u64_or arg_f64_result arg_f64_option arg_f64_or_zero arg_f64_or arg_bool_result arg_bool_option arg_bool_or_false arg_bool_or))

(fn impossible_index () -> i32
  99999)

(fn first_arg () -> string
  (arg 0))

(fn first_index () -> i32
  0)

(fn imported_arg_count_positive () -> bool
  (< 0 (argc)))

(fn imported_arg_result_oob_err_one () -> bool
  (match (arg_result (impossible_index))
    ((ok payload)
      false)
    ((err code)
      (= code 1))))

(fn imported_arg_option_flows_ok () -> bool
  (if (match (arg_option (first_index))
    ((some payload)
      (= payload (arg (first_index))))
    ((none)
      false))
    (match (arg_option (impossible_index))
      ((some payload)
        false)
      ((none)
        true))
    false))

(fn imported_has_arg_zero () -> bool
  (has_arg 0))

(fn imported_arg_fallback_missing_ok () -> bool
  (if (= (arg_or (impossible_index) "fallback") "fallback")
    (= (arg_or_empty (impossible_index)) "")
    false))

(fn imported_arg_fallback_present_ok () -> bool
  (if (has_arg 0)
    (if (= (arg_or 0 "fallback") (arg 0))
      (= (arg_or_empty 0) (arg 0))
      false)
    false))

(fn imported_arg_i32_missing_err_one () -> bool
  (match (arg_i32_result (impossible_index))
    ((ok value)
      false)
    ((err code)
      (= code 1))))

(fn imported_arg_i32_present_invalid_zero () -> bool
  (= (arg_i32_or_zero (first_index)) 0))

(fn imported_arg_u32_missing_err_one () -> bool
  (match (arg_u32_result (impossible_index))
    ((ok value)
      false)
    ((err code)
      (= code 1))))

(fn imported_arg_u32_present_invalid_zero () -> bool
  (= (arg_u32_or_zero (first_index)) 0u32))

(fn imported_arg_i64_missing_err_one () -> bool
  (match (arg_i64_result (impossible_index))
    ((ok value)
      false)
    ((err code)
      (= code 1))))

(fn imported_arg_i64_present_invalid_zero () -> bool
  (= (arg_i64_or_zero (first_index)) 0i64))

(fn imported_arg_u64_missing_err_one () -> bool
  (match (arg_u64_result (impossible_index))
    ((ok value)
      false)
    ((err code)
      (= code 1))))

(fn imported_arg_u64_present_invalid_zero () -> bool
  (= (arg_u64_or_zero (first_index)) 0u64))

(fn imported_arg_f64_missing_err_one () -> bool
  (match (arg_f64_result (impossible_index))
    ((ok value)
      false)
    ((err code)
      (= code 1))))

(fn imported_arg_f64_present_invalid_zero () -> bool
  (= (arg_f64_or_zero (first_index)) 0.0))

(fn imported_arg_bool_missing_err_one () -> bool
  (match (arg_bool_result (impossible_index))
    ((ok value)
      false)
    ((err code)
      (= code 1))))

(fn imported_arg_bool_present_invalid_false () -> bool
  (if (arg_bool_or_false (first_index))
    false
    true))

(fn imported_arg_typed_options_ok () -> bool
  (if (match (arg_i32_option (impossible_index))
    ((some value)
      false)
    ((none)
      true))
    (if (match (arg_i32_option (first_index))
      ((some value)
        false)
      ((none)
        true))
      (if (match (arg_u32_option (impossible_index))
        ((some value)
          false)
        ((none)
          true))
        (if (match (arg_u32_option (first_index))
          ((some value)
            false)
          ((none)
            true))
          (if (match (arg_i64_option (impossible_index))
            ((some value)
              false)
            ((none)
              true))
            (if (match (arg_i64_option (first_index))
              ((some value)
                false)
              ((none)
                true))
              (if (match (arg_u64_option (impossible_index))
                ((some value)
                  false)
                ((none)
                  true))
                (if (match (arg_u64_option (first_index))
                  ((some value)
                    false)
                  ((none)
                    true))
                  (if (match (arg_f64_option (impossible_index))
                    ((some value)
                      false)
                    ((none)
                      true))
                    (if (match (arg_f64_option (first_index))
                      ((some value)
                        false)
                      ((none)
                        true))
                      (if (match (arg_bool_option (impossible_index))
                        ((some value)
                          false)
                        ((none)
                          true))
                        (match (arg_bool_option (first_index))
                          ((some value)
                            false)
                          ((none)
                            true))
                        false)
                      false)
                    false)
                  false)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

(fn imported_arg_typed_custom_fallbacks_ok () -> bool
  (if (= (arg_i32_or (impossible_index) 7) 7)
    (if (= (arg_i32_or (first_index) 7) 7)
      (if (= (arg_u32_or (impossible_index) 7u32) 7u32)
        (if (= (arg_u32_or (first_index) 7u32) 7u32)
          (if (= (arg_i64_or (impossible_index) 9i64) 9i64)
            (if (= (arg_i64_or (first_index) 9i64) 9i64)
              (if (= (arg_u64_or (impossible_index) 9u64) 9u64)
                (if (= (arg_u64_or (first_index) 9u64) 9u64)
                  (if (= (arg_f64_or (impossible_index) 1.5) 1.5)
                    (if (= (arg_f64_or (first_index) 1.5) 1.5)
                      (if (arg_bool_or (impossible_index) true)
                        (arg_bool_or (first_index) true)
                        false)
                      false)
                    false)
                  false)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

(fn imported_process_facade_ok () -> bool
  (if (imported_arg_count_positive)
    (if (imported_arg_result_oob_err_one)
      (if (imported_arg_option_flows_ok)
        (if (imported_has_arg_zero)
          (if (imported_arg_fallback_missing_ok)
            (if (imported_arg_fallback_present_ok)
              (if (imported_arg_i32_missing_err_one)
                (if (imported_arg_i32_present_invalid_zero)
                  (if (imported_arg_u32_missing_err_one)
                    (if (imported_arg_u32_present_invalid_zero)
                      (if (imported_arg_i64_missing_err_one)
                        (if (imported_arg_i64_present_invalid_zero)
                          (if (imported_arg_u64_missing_err_one)
                            (if (imported_arg_u64_present_invalid_zero)
                              (if (imported_arg_f64_missing_err_one)
                                (if (imported_arg_f64_present_invalid_zero)
                                  (if (imported_arg_bool_missing_err_one)
                                    (if (imported_arg_bool_present_invalid_false)
                                      (if (imported_arg_typed_options_ok)
                                        (imported_arg_typed_custom_fallbacks_ok)
                                        false)
                                      false)
                                    false)
                                  false)
                                false)
                              false)
                            false)
                          false)
                        false)
                      false)
                    false)
                  false)
                false)
              false)
            false)
          false)
        false)
      false)
    false))

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

(test "explicit std process argc facade"
  (imported_arg_count_positive))

(test "explicit std process arg result oob facade"
  (imported_arg_result_oob_err_one))

(test "explicit std process arg option facade"
  (imported_arg_option_flows_ok))

(test "explicit std process has arg facade"
  (imported_has_arg_zero))

(test "explicit std process arg fallback missing facade"
  (imported_arg_fallback_missing_ok))

(test "explicit std process arg fallback present facade"
  (imported_arg_fallback_present_ok))

(test "explicit std process arg i32 missing facade"
  (imported_arg_i32_missing_err_one))

(test "explicit std process arg i32 invalid fallback facade"
  (imported_arg_i32_present_invalid_zero))

(test "explicit std process arg u32 missing facade"
  (imported_arg_u32_missing_err_one))

(test "explicit std process arg u32 invalid fallback facade"
  (imported_arg_u32_present_invalid_zero))

(test "explicit std process arg i64 missing facade"
  (imported_arg_i64_missing_err_one))

(test "explicit std process arg i64 invalid fallback facade"
  (imported_arg_i64_present_invalid_zero))

(test "explicit std process arg u64 missing facade"
  (imported_arg_u64_missing_err_one))

(test "explicit std process arg u64 invalid fallback facade"
  (imported_arg_u64_present_invalid_zero))

(test "explicit std process arg f64 missing facade"
  (imported_arg_f64_missing_err_one))

(test "explicit std process arg f64 invalid fallback facade"
  (imported_arg_f64_present_invalid_zero))

(test "explicit std process arg bool missing facade"
  (imported_arg_bool_missing_err_one))

(test "explicit std process arg bool invalid fallback facade"
  (imported_arg_bool_present_invalid_false))

(test "explicit std process typed option facade"
  (imported_arg_typed_options_ok))

(test "explicit std process typed custom fallback facade"
  (imported_arg_typed_custom_fallbacks_ok))

(test "explicit std process facade all"
  (= (main) 42))
