import type { LocalizedString } from './shared-types';
import { dataSets, loadModels } from './loadModels';

export interface Group {
  readonly group_id: number;
  readonly category_id: number;
  readonly name: LocalizedString;
  readonly published: boolean;
  readonly icon_id?: number;
  readonly anchorable: boolean;
  readonly anchored: boolean;
  readonly fittable_non_singleton: boolean;
  readonly use_base_price: boolean;
  readonly type_ids?: number[];
}
export function getGroup(group_id: number) {
  if (!dataSets.loaded) loadModels();
  const data = dataSets.groups[String(group_id)];
  if (!data) throw new Error(`Group ID ${group_id} not found in reference data`);
  return data;
}

export function groupEveRefLink(group_id: number) {
  return `https://everef.net/groups/${group_id}`;
}

export function renderGroupEveRefLink(group: Group, locale: string = 'en') {
  return `[${group.name[locale] ?? group.name.en}](${groupEveRefLink(group.group_id)})`;
}
