import apiClient from "@/api/client";

export interface Blog {
	id?: number;
	title: string;
	writer: string;
	image?: string;
	content: any;
}

export const getAllBlogsApi = async () => {
	const res = await apiClient.get("/blogs");
	return res.data;
};

export const getBlogByIdApi = async (id: number) => {
	const res = await apiClient.get(`/blogs/${id}`);
	return res.data;
};

export const createBlogApi = async (data: Blog) => {
	const res = await apiClient.post("/blogs", data);
	return res.data;
};

export const updateBlogApi = async (id: number, data: Blog) => {
	const res = await apiClient.put(`/blogs/${id}`, data);
	return res.data;
};

export const deleteBlogApi = async (id: number) => {
	const res = await apiClient.delete(`/blogs/${id}`);
	return res.data;
};

/* IMAGE UPLOAD */
export const uploadImageApi = async (file: File) => {
	const formData = new FormData();
	formData.append("image", file);

	const res = await apiClient.post("/upload/image", formData, {
		headers: {
			"Content-Type": "multipart/form-data",
		},
	});

	return res.data;
};
