import type { components } from "@shared/api/__generated__/openapi.types"

import api from "@shared/api"

export type ProjectCreateBody = components["schemas"]["ProjectCreate"]
export type ProjectRead = components["schemas"]["ProjectRead"]

interface IUseCreateProjectParams {
	onSuccess?: (project: ProjectRead) => void
	onError?: (error: unknown) => void
}

export const useCreateProject = ({
	onSuccess,
	onError,
}: IUseCreateProjectParams = {}) => {
	return api.useMutation("post", "/api/projects/", {
		onSuccess: (project) => {
			onSuccess?.(project)
		},
		onError: (error) => {
			onError?.(error)
		},
	})
}
