

export type Grammar = {
  id: number;
  uri: string;
  rootRule?: Rule;
  rules: Rule[];
  files: FileHolder[];
  xmlGen?: string;
  jsgfGen?: string;
};
export type FileHolder = {
  id: number;
  content?: string;
  xml: boolean;
  size: number;
  generated: boolean;
};
export type Rule = {
  id: number;
  leftSymbol: string;
  rightSide: RightSide[];
  root: boolean;
};
export type RightSide = {
  part: string;
};

type GrammarFunctions = {
  deleteGr: (id: number) => Promise<void>;
  editGr: (Grammar: { uri: string; id: number }) => Promise<void>;
  addRule: (rule: Rule, grammarId: number) => Promise<void>;
  duplicateGr: (id: number) => Promise<void>;
} & FileFunctions & RuleEditFunctions;

type RuleEditFunctions={
  deleteRule: (
    ruleId: number,
    root: boolean,
    grammarId: number
  ) => Promise<void>;
  changeRule: (
    ruleId: number,
    rule: { leftSymbol: string | null; rightSide: RightSide[] | null },
    grammarId: number
  ) => Promise<void>;
  changeRoot: (id: number, grammarId: number, oldRule: Rule) => Promise<void>;
}
export type RuleViewWithEditInput = {
  grammar:Grammar,
  rule:Rule,
  masterRoot:boolean
}& RuleEditFunctions

export type GrammarListInput = {
  grammars: Grammar[];
} & GrammarFunctions;

export type GrammarViewInput = {
  grammar: Grammar;
} & GrammarFunctions;

export type FileViewInput = {
  grammar: Grammar;
} & FileFunctions;

type FileFunctions = {
  generateFile: (
    xml: boolean,
    grammarId: number,
    save: boolean
  ) => Promise<void>;
  fileToGrammar: (
    file: string,
    xml: boolean | null,
    grammarId: number,
    save: boolean,
    diff: boolean
  ) => Promise<void>;
  deleteFilesFromGrammar: (grammarId: number) => Promise<void>;
}& SimpleFileFunctions;

type SimpleFileFunctions={
  getFile: (id: number, grammarId: number) => Promise<void>;
  deleteFile: (fileId: number, grammarId: number) => Promise<void>;
}
export type FileOneViewInput = {
  file:FileHolder
  grammar:Grammar
} & SimpleFileFunctions

type FileInputFunction = {
  fileAdd: (
    file: string,
    xml: boolean | null,
    save: boolean,
    diff: boolean
  ) => void;
}
export type FileInputInput = {
  file: File | null;
  setFile: React.Dispatch<React.SetStateAction<File | null>>;
  setText: React.Dispatch<React.SetStateAction<string>>;
  text: string;
  newDiff: boolean;
}&FileInputFunction

export type GrammarAdderInput = {
  save: (uri: string, rules: Rule[], rootRule: Rule | null) => Promise<void>;
}&FileInputFunction

export type RuleInputToGrammarInput = {
  rule: Rule;
  setRule: React.Dispatch<React.SetStateAction<Rule>>;
  haveRoot: boolean;
}
export type RuleListInputAdderInput = {
    rules: Rule[];
    setRules: React.Dispatch<React.SetStateAction<Rule[]>>;
    setRoot: React.Dispatch<React.SetStateAction<number>>;
}

export type RuleViewInput ={ small: boolean; rule: Rule }