import { get } from '.';
import { GetSpellsResponse } from './spells.types';

interface GetSpellsParams {
  name?: string;
  like_name?: string;
  schools?: string[];
  levels?: number[];
  ritual?: boolean;
  concentration?: boolean;
  classes?: string[];
  damage_inflict?: string[];
  damage_resist?: string[];
  conditions?: string[];
  saving_throw?: string[];
  attack_type?: string[];
  limit?: number;
  page?: number;
}

export async function getSpells(params?: GetSpellsParams): Promise<GetSpellsResponse> {
  const response = await get('dnd/spells', {
    name: params?.name,
    like_name: params?.like_name,
    schools: params?.schools?.join(','),
    levels: params?.levels?.join(','),
    ritual: params?.ritual,
    concentration: params?.concentration,
    classes: params?.classes?.join(','),
    damage_inflict: params?.damage_inflict?.join(','),
    damage_resist: params?.damage_resist?.join(','),
    conditions: params?.conditions?.join(','),
    saving_throw: params?.saving_throw?.join(','),
    attack_type: params?.attack_type?.join(','),
    limit: params?.limit,
    page: params?.page
  });
  return response?.json() || { data: [] };
}
