// Auto-generated by AutoCRUD Web Generator
import { client } from '../../lib/client';
import type { Character, Skill } from '../types';
import type { ResourceMeta, RevisionInfo, FullResource, RevisionListResponse, RevisionListParams, SearchParams } from '../../types/api';

const BASE = '/character';

export const characterApi = {
  create: (data: Character) =>
    client.post<RevisionInfo>(BASE, data),

  list: (params?: SearchParams & { returns?: string }) =>
    client.get<FullResource<Character>[]>(BASE, { params }),

  count: (params?: SearchParams) =>
    client.get<number>(`${BASE}/count`, { params }),

  get: (id: string, params?: { revision_id?: string; partial?: string[]; returns?: string }) =>
    client.get<FullResource<Character>>(`${BASE}/${id}`, { params }),

  update: (id: string, data: Character, params?: { change_status?: string; mode?: string }) =>
    client.put<RevisionInfo>(`${BASE}/${id}`, data, { params }),

  delete: (id: string) =>
    client.delete<ResourceMeta>(`${BASE}/${id}`),

  restore: (id: string) =>
    client.post<ResourceMeta>(`${BASE}/${id}/restore`),

  revisionList: (id: string, params?: RevisionListParams) =>
    client.get<RevisionListResponse>(`${BASE}/${id}/revision-list`, { params }),

  switchRevision: (id: string, revisionId: string) =>
    client.post<ResourceMeta>(`${BASE}/${id}/switch/${revisionId}`),

  createNewCharacter1: (allParams: Record<string, unknown>) =>
    client.post<RevisionInfo>(`/character/${allParams['name'] as string}/new`, null),

  createNewCharacter2: (allParams: Record<string, unknown>) => {
    const params = { name: allParams['name'] };
    return client.post<RevisionInfo>('/character/create-new-character2', null, { params });
  },

  createNewCharacter4: (data: Skill) =>
    client.post<RevisionInfo>('/character/create-new-character4', data),
};
