import { api } from "@/lib/api-client";
import type { BrandingConfig, EntityBranding } from "@/types";
import type { ApiSuccessResponse } from "@/types";

export const brandingService = {
  get: (entityId: number) =>
    api.get<EntityBranding>(`/entity/${entityId}/branding`),

  update: (entityId: number, data: BrandingConfig) =>
    api.put<ApiSuccessResponse>(`/entity/${entityId}/branding`, data),

  resetToDefault: (entityId: number) =>
    api.post<ApiSuccessResponse>(`/entity/${entityId}/branding/reset`),

  getCurrentBranding: () =>
    api.get<EntityBranding>("/entity/branding"),

  uploadLogo: (entityId: number, file: File) => {
    const formData = new FormData();
    formData.append("logo", file);
    return api.upload<{ url: string }>(`/entity/${entityId}/branding/logo`, formData);
  },

  uploadFavicon: (entityId: number, file: File) => {
    const formData = new FormData();
    formData.append("favicon", file);
    return api.upload<{ url: string }>(`/entity/${entityId}/branding/favicon`, formData);
  },
};
