import { ArticleDetailDataType } from "@/types/article";
import { JobDetailDataType } from "@/types/job";


// Hàm chung để gọi API
const apiRequest = async (endpoint: string, method: string = "GET", body?: object) => {
    const response = await fetch(`http://localhost:5000${endpoint}`, {
        method,
        headers: {
            "Content-Type": "application/json",
        },
        body: body ? JSON.stringify(body) : null,
    });

    if (!response.ok) throw new Error(`Error: ${response.statusText}`);
    return response.json();
};
// API cho bài viết
export const fetchListArticles = () => apiRequest("/list_article");
export const fetchArticleDetail = async (slug: string): Promise<ArticleDetailDataType> => {
    return apiRequest(`/articleDetails?path=${slug}`);
};

// API cho công việc
export const fetchListJobs = () => apiRequest("/list_job");
export const fetchJobDetail = async (slug: string): Promise<JobDetailDataType> => {
    return apiRequest(`/jobDetails?path=${slug}`);
};