// dashboard-v6/src/api/Dict.ts

import type { IStudio, IUser } from "./Auth";

export interface IDict {
  word?: string;
}

export interface ICaseListData {
  word: string;
  count: number;
  bold: number;
}
export interface IDictRequest {
  id?: number;
  word: string;
  type?: string | null;
  grammar?: string | null;
  mean?: string | null;
  parent?: string | null;
  parent2?: string | null;
  note?: string | null;
  factors?: string | null;
  factormean?: string | null;
  confidence: number;
  dict_id?: string;
  dict_name?: string;
  language?: string;
  creator_id?: number;
  editor?: IUser;
  studio?: IStudio;
  status?: number;
  updated_at?: string;
}
export interface IUserDictCreate {
  data: string;
  view: string;
}
export interface IDictResponse {
  ok: boolean;
  message: string;
  data: number[];
}
export interface IDictInfo {
  id: string;
  name: string;
  shortname: string;
}
export interface IApiResponseDictData {
  id: string;
  sn?: number;
  word: string;
  type?: string | null;
  grammar?: string | null;
  mean?: string | null;
  parent?: string | null;
  note?: string | null;
  factors?: string | null;
  factormean?: string | null;
  source: string | null;
  language: string;
  dict?: IDictInfo;
  dict_id: string;
  dict_name?: string;
  dict_shortname?: string;
  shortname?: string;
  confidence: number;
  creator_id: number;
  updated_at: string;
  exp?: number;
  editor?: IUser;
  status?: number;
  count?: number;
  created_at?: string;
}
export interface IApiResponseDict {
  ok: boolean;
  message: string;
  data: IApiResponseDictData;
}
export interface IApiResponseDictList {
  ok: boolean;
  message: string;
  data: {
    rows: IApiResponseDictData[];
    count: number;
    time?: number;
  };
}

export interface IVocabularyData {
  word: string;
  count: number;
  meaning?: string;
  strlen: number;
}
export interface IVocabularyListResponse {
  ok: boolean;
  message: string;
  data: {
    rows: IVocabularyData[];
    count: number;
  };
}

export interface IUserDictDeleteRequest {
  id: string;
}

export interface ICaseItem {
  word: string;
  case: ICaseListData[];
  count: number;
}
export interface ICaseListResponse {
  ok: boolean;
  message: string;
  data: {
    rows: ICaseItem[];
    count: number;
  };
}

export interface IFirstMeaning {
  word?: string;
  meaning?: string;
}
export interface IDictFirstMeaningResponse {
  ok: boolean;
  message: string;
  data: IFirstMeaning[];
}

export interface IPreferenceListResponse {
  ok: boolean;
  message: string;
  data: { rows: IApiResponseDictData[]; count: number };
}
export interface IPreferenceRequest {
  id?: string;
  word?: string;
  factors?: string | null;
  parent?: string | null;
  confidence?: number;
}
export interface IPreferenceResponse {
  ok: boolean;
  message: string;
  data: IApiResponseDictData;
}

export interface IWordGrammar {
  word: string;
  type: string;
  grammar: string;
  parent: string;
  factors: string;
  confidence: number;
}

export interface IWordByDict {
  dictname: string;
  description?: string;
  meta?: IDictInfo;
  word?: string;
  note?: string;
  anchor: string;
}
export interface IDictInfo {
  author: string;
  publisher: string;
  published?: string;
  url: string;
}

export interface IWordCardData {
  word: string;
  factors: string;
  parents: string;
  case?: string[];
  grammar: IWordGrammar[];
  anchor: string;
  dict: IWordByDict[];
}

export interface IDictWords {
  pass: string;
  words: IWordCardData[];
}

export interface IAnchorData {
  href: string;
  title: string;
  children?: IAnchorData[];
}

export interface IDictContentData {
  dictlist: IAnchorData[];
  words: IDictWords[];
  caselist: ICaseListData[];
  time?: number;
  count?: number;
}
export interface IApiDictContentData {
  ok: boolean;
  message: string;
  data: IDictContentData;
}

import { get } from "../request";

export const fetchDictByWord = (word: string): Promise<IApiDictContentData> => {
  const url = `/api/v2/dict?word=${word}`;
  return get<IApiDictContentData>(url);
};
