// Auto-generated by AutoCRUD Web Generator
import { client } from '../../lib/client';

export type OnDuplicate = 'overwrite' | 'skip' | 'raise_error';

export interface ImportResult {
  loaded: number;
  skipped: number;
  total: number;
}

export interface GlobalImportResult {
  [model: string]: ImportResult;
}

export const backupApi = {
  /** Download full backup (.acbak) for all models — uses the AutoCRUD global /_backup endpoint */
  exportAll: (models?: string[]) =>
    client.get('/_backup/export', {
      params: models ? { models } : undefined,
      responseType: 'blob',
    }),

  /** Upload .acbak archive (global import) — uses the AutoCRUD global /_backup endpoint */
  importAll: (file: File, onDuplicate: OnDuplicate = 'overwrite') => {
    const form = new FormData();
    form.append('file', file);
    return client.post<GlobalImportResult>('/_backup/import', form, {
      headers: { 'Content-Type': 'multipart/form-data' },
      params: { on_duplicate: onDuplicate },
    });
  },

  /** Export Character data as .acbak archive */
  exportCharacter: (params?: Record<string, unknown>) =>
    client.get(`/character/export`, { params, responseType: 'blob' }),

  /** Import .acbak archive into Character */
  importCharacter: (file: File, onDuplicate: OnDuplicate = 'overwrite') => {
    const form = new FormData();
    form.append('file', file);
    return client.post<ImportResult>(`/character/import`, form, {
      headers: { 'Content-Type': 'multipart/form-data' },
      params: { on_duplicate: onDuplicate },
    });
  },

  /** Export Guild data as .acbak archive */
  exportGuild: (params?: Record<string, unknown>) =>
    client.get(`/guild/export`, { params, responseType: 'blob' }),

  /** Import .acbak archive into Guild */
  importGuild: (file: File, onDuplicate: OnDuplicate = 'overwrite') => {
    const form = new FormData();
    form.append('file', file);
    return client.post<ImportResult>(`/guild/import`, form, {
      headers: { 'Content-Type': 'multipart/form-data' },
      params: { on_duplicate: onDuplicate },
    });
  },

  /** Export Skill data as .acbak archive */
  exportSkill: (params?: Record<string, unknown>) =>
    client.get(`/skill/export`, { params, responseType: 'blob' }),

  /** Import .acbak archive into Skill */
  importSkill: (file: File, onDuplicate: OnDuplicate = 'overwrite') => {
    const form = new FormData();
    form.append('file', file);
    return client.post<ImportResult>(`/skill/import`, form, {
      headers: { 'Content-Type': 'multipart/form-data' },
      params: { on_duplicate: onDuplicate },
    });
  },

  /** Export Equipment data as .acbak archive */
  exportEquipment: (params?: Record<string, unknown>) =>
    client.get(`/equipment/export`, { params, responseType: 'blob' }),

  /** Import .acbak archive into Equipment */
  importEquipment: (file: File, onDuplicate: OnDuplicate = 'overwrite') => {
    const form = new FormData();
    form.append('file', file);
    return client.post<ImportResult>(`/equipment/import`, form, {
      headers: { 'Content-Type': 'multipart/form-data' },
      params: { on_duplicate: onDuplicate },
    });
  },

  /** Export Pet Job data as .acbak archive */
  exportPetJob: (params?: Record<string, unknown>) =>
    client.get(`/pet-job/export`, { params, responseType: 'blob' }),

  /** Import .acbak archive into Pet Job */
  importPetJob: (file: File, onDuplicate: OnDuplicate = 'overwrite') => {
    const form = new FormData();
    form.append('file', file);
    return client.post<ImportResult>(`/pet-job/import`, form, {
      headers: { 'Content-Type': 'multipart/form-data' },
      params: { on_duplicate: onDuplicate },
    });
  },

  /** Export Game Event data as .acbak archive */
  exportGameEvent: (params?: Record<string, unknown>) =>
    client.get(`/game-event/export`, { params, responseType: 'blob' }),

  /** Import .acbak archive into Game Event */
  importGameEvent: (file: File, onDuplicate: OnDuplicate = 'overwrite') => {
    const form = new FormData();
    form.append('file', file);
    return client.post<ImportResult>(`/game-event/import`, form, {
      headers: { 'Content-Type': 'multipart/form-data' },
      params: { on_duplicate: onDuplicate },
    });
  },

  /** Export Pet data as .acbak archive */
  exportPet: (params?: Record<string, unknown>) =>
    client.get(`/pet/export`, { params, responseType: 'blob' }),

  /** Import .acbak archive into Pet */
  importPet: (file: File, onDuplicate: OnDuplicate = 'overwrite') => {
    const form = new FormData();
    form.append('file', file);
    return client.post<ImportResult>(`/pet/import`, form, {
      headers: { 'Content-Type': 'multipart/form-data' },
      params: { on_duplicate: onDuplicate },
    });
  },
};
