import { apiInstance } from "@/shared/config/apiConfig";
import { IList } from "@/shared/types/list-type";
import { INews } from "@/shared/types/news-type";
import { AxiosError } from "axios";

interface IFetchNews extends IList {
  results: INews[];
}

export const getNews = async () => {
  try {
    const data = (await apiInstance.get<IFetchNews>("/news/")).data;

    return data.results.slice(0, 4);
  } catch (error: unknown) {
    if (error instanceof AxiosError) {
      console.log(error.message);
    } else {
      console.log("An error ocured");
    }
  }
};
