import { Button, Text, View } from "react-native";
import { AtomRpc, useAtomSet } from "@effect-atom/atom-react";
import { Layer } from "effect";
import { LinkRpcs } from "@money/shared/rpc";
import { FetchHttpClient } from "@effect/platform";
import { RpcClient, RpcSerialization } from "@effect/rpc";

class Client extends AtomRpc.Tag<Client>()("RpcClient", {
  group: LinkRpcs,
  protocol: RpcClient.layerProtocolHttp({
    url: "http://laptop:3000/rpc",
  }).pipe(Layer.provide([RpcSerialization.layerJson, FetchHttpClient.layer])),
}) {}

export default function Page() {
  const create = useAtomSet(Client.mutation("CreateLink"));

  const onPress = () => {
    create({
      payload: void 0,
    });
  };

  return (
    <View>
      <Text>RPC Test</Text>
      <Button onPress={onPress} title="Create link" />
    </View>
  );
}
