import apiClient from "@/lib/axiosClient";
import { API_ENDPOINTS } from "@/lib/apiEndpoints";
import { ApiResponse } from "@/types/api";
import { Category } from "@/types/home";

interface RawCategory {
  id: number;
  name: string;
  image: string;
  storage_type: number;
  sort_order: number;
  status: number;
}

export const categoryService = {
  getCategories: (): Promise<ApiResponse<RawCategory[]>> =>
    apiClient.post(API_ENDPOINTS.GET_CATEGORY).then((r) => r.data),

  mapCategory: (raw: RawCategory): Category => ({
    id: raw.id,
    name: raw.name,
    image: raw.image,
    storageType: raw.storage_type,
    sortOrder: raw.sort_order,
    status: raw.status,
  }),
};
