(* Generated by coq-of-rust *)
Require Import CoqOfRust.CoqOfRust.

Axiom Hash :
  (Ty.path "call_builder_delegate::Hash") =
    (Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 32 ] [ Ty.path "u8" ]).

(*
Enum LangError
{
  const_params := [];
  ty_params := [];
  variants :=
    [
      {
        name := "CouldNotReadInput";
        item := StructTuple [];
        discriminant := None;
      }
    ];
}
*)

(* StructRecord
  {
    name := "CallBuilderDelegateTest";
    const_params := [];
    ty_params := [];
    fields := [ ("value", Ty.path "i32") ];
  } *)

Module Impl_core_default_Default_for_call_builder_delegate_CallBuilderDelegateTest.
  Definition Self : Ty.t := Ty.path "call_builder_delegate::CallBuilderDelegateTest".
  
  (* Default *)
  Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [] =>
      ltac:(M.monadic
        (Value.StructRecord
          "call_builder_delegate::CallBuilderDelegateTest"
          [
            ("value",
              M.call_closure (|
                M.get_trait_method (| "core::default::Default", Ty.path "i32", [], "default", [] |),
                []
              |))
          ]))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Implements :
    M.IsTraitInstance
      "core::default::Default"
      Self
      (* Trait polymorphic types *) []
      (* Instance *) [ ("default", InstanceField.Method default) ].
End Impl_core_default_Default_for_call_builder_delegate_CallBuilderDelegateTest.

Module Impl_call_builder_delegate_CallBuilderDelegateTest.
  Definition Self : Ty.t := Ty.path "call_builder_delegate::CallBuilderDelegateTest".
  
  (*
      pub fn new(value: i32) -> Self {
          Self { value }
      }
  *)
  Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ value ] =>
      ltac:(M.monadic
        (let value := M.alloc (| value |) in
        Value.StructRecord
          "call_builder_delegate::CallBuilderDelegateTest"
          [ ("value", M.read (| value |)) ]))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom AssociatedFunction_new : M.IsAssociatedFunction Self "new" new.
  
  (*
      pub fn delegate(&mut self, code_hash: Hash, selector: [u8; 4]) -> Option<LangError> {
          // let result = build_call::<DefaultEnvironment>()
          //     .delegate(code_hash)
          //     .exec_input(ExecutionInput::new(Selector::new(selector)))
          //     .returns::<bool>()
          //     .try_invoke()
          //     .expect("Error from the Contracts pallet.");
  
          // match result {
          //     Ok(_) => None,
          //     Err(e @ ink::LangError::CouldNotReadInput) => Some(e),
          //     Err(_) => {
          //         unimplemented!("No other `LangError` variants exist at the moment.")
          //     }
          // }
          None
      }
  *)
  Definition delegate (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self; code_hash; selector ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        let code_hash := M.alloc (| code_hash |) in
        let selector := M.alloc (| selector |) in
        Value.StructTuple "core::option::Option::None" []))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom AssociatedFunction_delegate : M.IsAssociatedFunction Self "delegate" delegate.
  
  (*
      pub fn invoke(&mut self, code_hash: Hash, selector: [u8; 4]) -> i32 {
          // use ink::env::call::build_call;
  
          // build_call::<DefaultEnvironment>()
          //     .delegate(code_hash)
          //     .exec_input(ExecutionInput::new(Selector::new(selector)))
          //     .returns::<i32>()
          //     .invoke()
          0
      }
  *)
  Definition invoke (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ self; code_hash; selector ] =>
      ltac:(M.monadic
        (let self := M.alloc (| self |) in
        let code_hash := M.alloc (| code_hash |) in
        let selector := M.alloc (| selector |) in
        Value.Integer IntegerKind.I32 0))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom AssociatedFunction_invoke : M.IsAssociatedFunction Self "invoke" invoke.
End Impl_call_builder_delegate_CallBuilderDelegateTest.
