import { createAsyncThunk } from "@reduxjs/toolkit";
import MainApi from "../../utils/api";

const api = new MainApi("https://a1.coord.graff.tech");


export const fetchCards = createAsyncThunk(
  "cards/FetchAll",
  async (_, thunkAPI) => {
    try {
      const response = await api.getRC();
      return response;
    } catch (e) {
      return thunkAPI.rejectWithValue("Нет доступных демонстраций");
    }
  }
);

export const createSession = createAsyncThunk(
  "session/Create",
  async (title: string, thunkApi) => {
    try {
      const response = await api.createSession(title);
      return response;
    } catch (e) {
      return thunkApi.rejectWithValue("Произошла ошибка");
    }
  }
);

export const connectSession = createAsyncThunk(
  "session/Create",
  async (code: string, thunkApi) => {
    try {
      const response = await api.connectSession(code);
      return response;
    } catch (e) {
      return thunkApi.rejectWithValue("Произошла ошибка");
    }
  }
);
