// /redux/thunks/fetchLast20MessagesThunk.ts
import { createAsyncThunk } from "@reduxjs/toolkit";
import { fetchLast20MessagesFromWindow } from "../../services/fetchLast20MessagesService";
import { setLast20Messages } from "../slices/last20MessagesSlice";

export const fetchLast20MessagesThunk = createAsyncThunk(
  "last20Messages/fetchLast20Messages",
  async (_, { dispatch }) => {
    const messages = await fetchLast20MessagesFromWindow();
    dispatch(setLast20Messages(messages));
    return messages;
  }
);
