import axios from "axios";
import { getStoredLocale } from "../getLocale";

export async function indexTag(
  token: string,
  { page = 1, limit = 1000 }: { page?: number; limit?: number }
): Promise<any> {
  try {
    const locale = getStoredLocale();

    const url = `${process.env.NEXT_PUBLIC_API_URL}/tags?page=${page}&limit=${limit}`;

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      "Accept-Language": locale,
      Authorization: "Bearer " + token,
    };

    const res = await axios.get(url, { headers });
    const result = res?.data?.data;

    return {
      success: true,
      message: "Tags Fetched Successfully!",
      data: result,
    };
  } catch (error: any) {
    throw error;
  }
}

export async function indexBrand(
  token: string,
  { page = 1, limit = 1000 }: { page?: number; limit?: number }
): Promise<any> {
  try {
    const locale = getStoredLocale();

    const url = `${process.env.NEXT_PUBLIC_API_URL}/brands?page=${page}&limit=${limit}`;

    const headers: Record<string, string> = {
      "Content-Type": "application/json",
      "Accept-Language": locale,
      Authorization: "Bearer " + token,
    };

    const res = await axios.get(url, { headers });
    const result = res?.data?.data;

    return {
      success: true,
      message: "Brands Fetched Successfully!",
      data: result,
    };
  } catch (error: any) {
    throw error;
  }
}
