export interface UnknownFieldsObject {
    groups?: NodeObject[]
    [key: string]:
        | NodeObject[]
        | RangeArray[]
        | NodeArray[]
        | Array<NodeArray | string>
        | NameDictObject[]
        | string
        | undefined
}

export interface MarkObject {
    type: string
}

interface OtherNodeObject {
    type: string
    marks?: MarkObject[]
    attrs?: Record<string, unknown>
}

export interface TextNodeObject {
    type: "text"
    text: string
    marks?: MarkObject[]
    attrs?: Record<string, unknown>
}

export type NodeObject = OtherNodeObject | TextNodeObject

export type NodeArray = NodeObject[]

export interface EntryLocation {
    start: number
    end: number
}

export interface EntryObject {
    entry_key: string
    incomplete?: boolean
    bib_type: string
    location?: EntryLocation
    raw_text?: string
    fields: Record<string, unknown>
    unexpected_fields?: Record<string, unknown>
    unknown_fields?: UnknownFieldsObject
}

export type NameDictObject = {
    literal?: NodeArray
    family?: NodeArray
    given?: NodeArray
    prefix?: NodeArray
    suffix?: NodeArray
    useprefix?: boolean
}

export type GroupObject = {
    name: string
    references: string[]
    groups: GroupObject[]
}

export type RangeArray = [NodeArray, NodeArray] | [NodeArray]

export interface LangidOptions {
    [key: string]: {
        csl: string
        biblatex: string
    }
}

/** A list of supported languages (without aliases)  in the langid field */
const langidOptions: LangidOptions = {
    acadian: {
        csl: "fr-CA",
        biblatex: "acadian",
    },
    afrikaans: {
        csl: "af-ZA",
        biblatex: "afrikaans",
    },
    arabic: {
        csl: "ar",
        biblatex: "arabic",
    },
    basque: {
        csl: "eu",
        biblatex: "basque",
    },
    bulgarian: {
        csl: "bg-BG",
        biblatex: "bulgarian",
    },
    catalan: {
        csl: "ca-AD",
        biblatex: "catalan",
    },
    chinese: {
        csl: "zh-CN",
        biblatex: "pinyin",
    },
    croatian: {
        csl: "hr-HR",
        biblatex: "croatian",
    },
    czech: {
        csl: "cs-CZ",
        biblatex: "czech",
    },
    danish: {
        csl: "da-DK",
        biblatex: "danish",
    },
    dutch: {
        csl: "nl-NL",
        biblatex: "dutch",
    },
    auenglish: {
        csl: "en-GB",
        biblatex: "australian",
    },
    caenglish: {
        csl: "en-US",
        biblatex: "canadian",
    },
    nzenglish: {
        csl: "en-GB",
        biblatex: "newzealand",
    },
    ukenglish: {
        csl: "en-GB",
        biblatex: "ukenglish",
    },
    usenglish: {
        csl: "en-US",
        biblatex: "usenglish",
    },
    estonian: {
        csl: "et-EE",
        biblatex: "estonian",
    },
    finnish: {
        csl: "fi-FI",
        biblatex: "finnish",
    },
    french: {
        csl: "fr-FR",
        biblatex: "french",
    },
    cafrench: {
        csl: "fr-CA",
        biblatex: "canadien",
    },
    german: {
        csl: "de-DE",
        biblatex: "ngerman",
    },
    atgerman: {
        csl: "de-AT",
        biblatex: "naustrian",
    },
    greek: {
        csl: "el-GR",
        biblatex: "greek",
    },
    hebrew: {
        csl: "he-IL",
        biblatex: "hebrew",
    },
    hungarian: {
        csl: "hu-HU",
        biblatex: "hungarian",
    },
    icelandic: {
        csl: "is-IS",
        biblatex: "icelandic",
    },
    italian: {
        csl: "it-IT",
        biblatex: "italian",
    },
    japanese: {
        csl: "ja-JP",
        biblatex: "japanese",
    },
    latin: {
        csl: "la",
        biblatex: "latin",
    },
    latvian: {
        csl: "lv-LV",
        biblatex: "latvian",
    },
    lithuanian: {
        csl: "lt-LT",
        biblatex: "lithuanian",
    },
    magyar: {
        csl: "hu-HU",
        biblatex: "magyar",
    },
    mongolian: {
        csl: "mn-MN",
        biblatex: "mongolian",
    },
    norwegian: {
        csl: "nb-NO",
        biblatex: "norsk",
    },
    newnorwegian: {
        csl: "nn-NO",
        biblatex: "nynorsk",
    },
    farsi: {
        csl: "fa-IR",
        biblatex: "farsi",
    },
    polish: {
        csl: "pl-PL",
        biblatex: "polish",
    },
    portuguese: {
        csl: "pt-PT",
        biblatex: "portuguese",
    },
    brportuguese: {
        csl: "pt-BR",
        biblatex: "brazilian",
    },
    romanian: {
        csl: "ro-RO",
        biblatex: "romanian",
    },
    russian: {
        csl: "ru-RU",
        biblatex: "russian",
    },
    serbian: {
        csl: "sr-RS",
        biblatex: "serbian",
    },
    cyrillicserbian: {
        csl: "sr-RS",
        biblatex: "serbianc",
    },
    slovak: {
        csl: "sk-SK",
        biblatex: "slovak",
    },
    slovene: {
        csl: "sl-SL",
        biblatex: "slovene",
    },
    spanish: {
        csl: "es-ES",
        biblatex: "spanish",
    },
    swedish: {
        csl: "sv-SE",
        biblatex: "swedish",
    },
    thai: {
        csl: "th-TH",
        biblatex: "thai",
    },
    turkish: {
        csl: "tr-TR",
        biblatex: "turkish",
    },
    ukrainian: {
        csl: "uk-UA",
        biblatex: "ukrainian",
    },
    vietnamese: {
        csl: "vi-VN",
        biblatex: "vietnamese",
    },
}

const pubstateOptions: { [key: string]: { csl: string; biblatex: string } } = {
    inpreparation: {
        csl: "in preparation",
        biblatex: "inpreparation",
    },
    submitted: {
        csl: "submitted",
        biblatex: "submitted",
    },
    forthcoming: {
        csl: "forthcoming",
        biblatex: "forthcoming",
    },
    inpress: {
        csl: "in press",
        biblatex: "inpress",
    },
    prepublished: {
        csl: "prepublished",
        biblatex: "prepublished",
    },
}

const languageOptions = [
    "catalan",
    "croatian",
    "czech",
    "danish",
    "dutch",
    "english",
    "american",
    "finnish",
    "french",
    "german",
    "greek",
    "italian",
    "latin",
    "norwegian",
    "polish",
    "portuguese",
    "brazilian",
    "russian",
    "slovene",
    "spanish",
    "swedish",
]

interface BibFieldType {
    type: string
    biblatex: string
    csl?: string | Record<string, string>
    options?: string[] | LangidOptions
    strict?: boolean
}

/** A list of field types of Bibligraphy DB with lookup by field name. */
export const BibFieldTypes: Record<string, BibFieldType> = {
    abstract: {
        type: "f_long_literal",
        biblatex: "abstract",
        csl: "abstract",
    },
    addendum: {
        type: "f_literal",
        biblatex: "addendum",
    },
    afterword: {
        type: "l_name",
        biblatex: "afterword",
    },
    annotation: {
        type: "f_long_literal",
        biblatex: "annotation",
    },
    annotator: {
        type: "l_name",
        biblatex: "annotator",
    },
    author: {
        type: "l_name",
        biblatex: "author",
        csl: "author",
    },
    bookauthor: {
        type: "l_name",
        biblatex: "bookauthor",
        csl: "container-author",
    },
    bookpagination: {
        type: "f_key",
        biblatex: "bookpagination",
        options: ["page", "column", "section", "paragraph", "verse", "line"],
    },
    booksubtitle: {
        type: "f_title",
        biblatex: "booksubtitle",
    },
    booktitle: {
        type: "f_title",
        biblatex: "booktitle",
        csl: "container-title",
    },
    booktitleaddon: {
        type: "f_title",
        biblatex: "booktitleaddon",
    },
    chapter: {
        type: "f_literal",
        biblatex: "chapter",
        csl: "chapter-number",
    },
    commentator: {
        type: "l_name",
        biblatex: "commentator",
    },
    date: {
        type: "f_date",
        biblatex: "date",
        csl: "issued",
    },
    doi: {
        type: "f_verbatim",
        biblatex: "doi",
        csl: "DOI",
    },
    edition: {
        type: "f_integer",
        biblatex: "edition",
        csl: "edition",
    },
    editor: {
        type: "l_name",
        biblatex: "editor",
        csl: "editor",
    },
    editora: {
        type: "l_name",
        biblatex: "editora",
    },
    editorb: {
        type: "l_name",
        biblatex: "editorb",
    },
    editorc: {
        type: "l_name",
        biblatex: "editorc",
    },
    editortype: {
        // Not used
        type: "f_key",
        biblatex: "editortype",
        options: [
            "editor",
            "compiler",
            "founder",
            "continuator",
            "redactor",
            "reviser",
            "collaborator",
        ],
    },
    editoratype: {
        // Not used
        type: "f_key",
        biblatex: "editoratype",
        options: [
            "editor",
            "compiler",
            "founder",
            "continuator",
            "redactor",
            "reviser",
            "collaborator",
        ],
    },
    editorbtype: {
        // Not used
        type: "f_key",
        biblatex: "editorbtype",
        options: [
            "editor",
            "compiler",
            "founder",
            "continuator",
            "redactor",
            "reviser",
            "collaborator",
        ],
    },
    editorctype: {
        // Not used
        type: "f_key",
        biblatex: "editorctype",
        options: [
            "editor",
            "compiler",
            "founder",
            "continuator",
            "redactor",
            "reviser",
            "collaborator",
        ],
    },
    eid: {
        type: "f_literal",
        biblatex: "eid",
    },
    entrysubtype: {
        // Not used
        type: "f_literal",
        biblatex: "entrysubtype",
    },
    eprint: {
        type: "f_verbatim",
        biblatex: "eprint",
    },
    eprintclass: {
        type: "f_literal",
        biblatex: "eprintclass",
    },
    eprinttype: {
        type: "f_literal",
        biblatex: "eprinttype",
    },
    eventdate: {
        type: "f_date",
        biblatex: "eventdate",
        csl: "event-date",
    },
    eventtitle: {
        type: "f_title",
        biblatex: "eventtitle",
        csl: "event",
    },
    file: {
        // Not used
        type: "f_verbatim",
        biblatex: "file",
    },
    foreword: {
        type: "l_name",
        biblatex: "foreword",
    },
    holder: {
        type: "l_name",
        biblatex: "holder",
    },
    howpublished: {
        type: "f_literal",
        biblatex: "howpublished",
        csl: "medium",
    },
    indextitle: {
        // Not used
        type: "f_literal",
        biblatex: "indextitle",
    },
    institution: {
        type: "l_literal",
        biblatex: "institution",
    },
    introduction: {
        type: "l_name",
        biblatex: "introduction",
    },
    isan: {
        // Not used
        type: "f_literal",
        biblatex: "isan",
        csl: "number",
    },
    isbn: {
        type: "f_literal",
        biblatex: "isbn",
        csl: "ISBN",
    },
    ismn: {
        // Not used
        type: "f_literal",
        biblatex: "ismn",
        csl: "number",
    },
    isrn: {
        type: "f_literal",
        biblatex: "isrn",
        csl: "number",
    },
    issn: {
        type: "f_literal",
        biblatex: "issn",
        csl: "ISSN",
    },
    issue: {
        type: "f_literal",
        biblatex: "issue",
        csl: "issue",
    },
    issuesubtitle: {
        type: "f_literal",
        biblatex: "issuesubtitle",
    },
    issuetitle: {
        type: "f_literal",
        biblatex: "issuetitle",
    },
    iswc: {
        // Not used
        type: "f_literal",
        biblatex: "iswc",
        csl: "number",
    },
    journalsubtitle: {
        type: "f_literal",
        biblatex: "journalsubtitle",
    },
    journaltitle: {
        type: "f_title",
        biblatex: "journaltitle",
        csl: "container-title",
    },
    keywords: {
        type: "l_tag",
        biblatex: "keywords",
    },
    label: {
        // Not used
        type: "f_literal",
        biblatex: "label",
    },
    language: {
        type: "l_key",
        biblatex: "language",
        options: languageOptions,
    },
    langid: {
        type: "f_key",
        strict: true, // Does not allow costum strings
        biblatex: "langid",
        csl: "language",
        options: langidOptions,
    },
    library: {
        // Not used
        type: "f_literal",
        biblatex: "library",
    },
    location: {
        type: "l_literal",
        biblatex: "location",
        csl: "publisher-place",
    },
    mainsubtitle: {
        type: "f_title",
        biblatex: "mainsubtitle",
    },
    maintitle: {
        type: "f_title",
        biblatex: "maintitle",
    },
    maintitleaddon: {
        type: "f_title",
        biblatex: "maintitleaddon",
    },
    nameaddon: {
        // Not used
        type: "f_literal",
        biblatex: "nameaddon",
    },
    note: {
        type: "f_literal",
        biblatex: "note",
        csl: "note",
    },
    number: {
        type: "f_literal",
        biblatex: "number",
        csl: {
            "article-journal": "issue",
            patent: "number",
            "*": "collection-number",
        }, // See https://discourse.citationstyles.org/t/issue-number-and-bibtex/1072
    },
    organization: {
        type: "l_literal",
        biblatex: "organization",
    },
    origdate: {
        type: "f_date",
        biblatex: "origdate",
        csl: "original-date",
    },
    origlanguage: {
        type: "f_key",
        biblatex: "origlanguage",
        options: languageOptions,
    },
    origlocation: {
        type: "l_literal",
        biblatex: "origlocation",
        csl: "original-publisher-place",
    },
    origpublisher: {
        type: "l_literal",
        biblatex: "origpublisher",
        csl: "original-publisher",
    },
    origtitle: {
        type: "f_title",
        biblatex: "origtitle",
        csl: "original-title",
    },
    pages: {
        type: "l_range",
        biblatex: "pages",
        csl: "page",
    },
    pagetotal: {
        type: "f_literal",
        biblatex: "pagetotal",
        csl: "number-of-pages",
    },
    pagination: {
        type: "f_key",
        biblatex: "pagination",
        options: ["page", "column", "section", "paragraph", "verse", "line"],
    },
    part: {
        type: "f_literal",
        biblatex: "part",
    },
    publisher: {
        type: "l_literal",
        biblatex: "publisher",
        csl: "publisher",
    },
    pubstate: {
        type: "f_key",
        biblatex: "pubstate",
        csl: "status",
        options: pubstateOptions,
    },
    reprinttitle: {
        // Not used
        type: "f_literal",
        biblatex: "reprinttitle",
    },
    series: {
        type: "f_title",
        biblatex: "series",
        csl: "collection-title",
    },
    shortauthor: {
        // Not used
        type: "l_name",
        biblatex: "shortauthor",
    },
    shorteditor: {
        // Not used
        type: "l_name",
        biblatex: "shorteditor",
    },
    shorthand: {
        // Not used
        type: "f_literal",
        biblatex: "shorthand",
    },
    shorthandintro: {
        // Not used
        type: "f_literal",
        biblatex: "shorthandintro",
    },
    shortjournal: {
        // Not used
        type: "f_title",
        biblatex: "shortjournal",
        csl: "container-title-short",
    },
    shortseries: {
        // Not used
        type: "f_literal",
        biblatex: "shortseries",
    },
    shorttitle: {
        type: "f_title",
        biblatex: "shorttitle",
        csl: "title-short",
    },
    subtitle: {
        type: "f_title",
        biblatex: "subtitle",
    },
    title: {
        type: "f_title",
        biblatex: "title",
        csl: "title",
    },
    titleaddon: {
        type: "f_title",
        biblatex: "titleaddon",
    },
    translator: {
        type: "l_name",
        biblatex: "translator",
        csl: "translator",
    },
    type: {
        type: "f_key",
        biblatex: "type",
        options: [
            "manual",
            "patent",
            "report",
            "thesis",
            "mathesis",
            "phdthesis",
            "candthesis",
            "techreport",
            "resreport",
            "software",
            "datacd",
            "audiocd",
        ],
    },
    url: {
        type: "f_uri",
        biblatex: "url",
        csl: "URL",
    },
    urldate: {
        type: "f_date",
        biblatex: "urldate",
        csl: "accessed",
    },
    venue: {
        type: "f_literal",
        biblatex: "venue",
        csl: "event-place",
    },
    version: {
        type: "f_literal",
        biblatex: "version",
        csl: "version",
    },
    volume: {
        type: "f_literal",
        biblatex: "volume",
        csl: "volume",
    },
    volumes: {
        type: "f_literal",
        biblatex: "volumes",
        csl: "number-of-volumes",
    },
}

export interface BibType {
    order: number
    biblatex: string
    csl: string
    required: string[]
    eitheror: string[]
    optional: string[]
    "biblatex-subtype"?: string
}

/** A list of all bib types and their fields. */
export const BibTypes: Record<string, BibType> = {
    "article-journal": {
        order: 1,
        biblatex: "article",
        csl: "article-journal",
        required: ["journaltitle", "title", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "annotator",
            "commentator",
            "doi",
            "editor",
            "editora",
            "editorb",
            "editorc",
            "eid",
            "eprint",
            "eprintclass",
            "eprinttype",
            "issn",
            "issue",
            "issuesubtitle",
            "issuetitle",
            "journalsubtitle",
            "language",
            "note",
            "number",
            "pages",
            "pagination",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "version",
            "volume",
            "origdate",
            "origlanguage",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    "article-magazine": {
        order: 2,
        biblatex: "article",
        "biblatex-subtype": "magazine",
        csl: "article-magazine",
        required: ["journaltitle", "title", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "annotator",
            "commentator",
            "doi",
            "editor",
            "editora",
            "editorb",
            "editorc",
            "eid",
            "eprint",
            "eprintclass",
            "eprinttype",
            "issn",
            "issue",
            "issuesubtitle",
            "issuetitle",
            "journalsubtitle",
            "language",
            "note",
            "number",
            "pages",
            "pagination",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "version",
            "volume",
            "origdate",
            "origlanguage",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    "article-newspaper": {
        order: 3,
        biblatex: "article",
        "biblatex-subtype": "newspaper",
        csl: "article-newspaper",
        required: ["journaltitle", "title", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "annotator",
            "commentator",
            "doi",
            "editor",
            "editora",
            "editorb",
            "editorc",
            "eid",
            "eprint",
            "eprintclass",
            "eprinttype",
            "issn",
            "issue",
            "issuesubtitle",
            "issuetitle",
            "journalsubtitle",
            "language",
            "note",
            "number",
            "pages",
            "pagination",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "version",
            "volume",
            "origdate",
            "origlanguage",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    article: {
        order: 4,
        biblatex: "article",
        csl: "article",
        required: ["journaltitle", "title", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "annotator",
            "commentator",
            "doi",
            "editor",
            "editora",
            "editorb",
            "editorc",
            "eid",
            "eprint",
            "eprintclass",
            "eprinttype",
            "issn",
            "issue",
            "issuesubtitle",
            "issuetitle",
            "journalsubtitle",
            "language",
            "note",
            "number",
            "pages",
            "pagination",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "version",
            "volume",
            "origdate",
            "origlanguage",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    "post-weblog": {
        order: 5,
        biblatex: "online",
        csl: "post-weblog",
        required: ["date", "title", "url", "langid"],
        eitheror: ["editor", "author"],
        optional: [
            "abstract",
            "addendum",
            "pubstate",
            "shorttitle",
            "subtitle",
            "language",
            "urldate",
            "titleaddon",
            "version",
            "note",
            "organization",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    book: {
        order: 10,
        biblatex: "book",
        csl: "book",
        required: ["title", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "chapter",
            "commentator",
            "doi",
            "edition",
            "editor",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "pages",
            "pagination",
            "pagetotal",
            "bookpagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volume",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    mvbook: {
        order: 11,
        biblatex: "mvbook",
        csl: "book",
        required: ["title", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "commentator",
            "doi",
            "edition",
            "editor",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "note",
            "number",
            "pagetotal",
            "bookpagination",
            "publisher",
            "pubstate",
            "series",
            "subtitle",
            "shorttitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    inbook: {
        order: 12,
        biblatex: "inbook",
        csl: "chapter",
        required: ["title", "booktitle", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "bookauthor",
            "booksubtitle",
            "booktitleaddon",
            "chapter",
            "commentator",
            "doi",
            "edition",
            "editor",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "pages",
            "pagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volume",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    bookinbook: {
        order: 13,
        biblatex: "bookinbook",
        csl: "chapter",
        required: ["title", "booktitle", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "bookauthor",
            "booksubtitle",
            "booktitleaddon",
            "chapter",
            "commentator",
            "doi",
            "edition",
            "editor",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "pages",
            "pagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volume",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    suppbook: {
        order: 14,
        biblatex: "suppbook",
        csl: "chapter",
        required: ["title", "booktitle", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "bookauthor",
            "booksubtitle",
            "booktitleaddon",
            "chapter",
            "commentator",
            "doi",
            "edition",
            "editor",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "pages",
            "pagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volume",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    booklet: {
        order: 15,
        biblatex: "booklet",
        csl: "pamphlet",
        required: ["title", "date", "langid"],
        eitheror: ["editor", "author"],
        optional: [
            "abstract",
            "titleaddon",
            "addendum",
            "pages",
            "pagination",
            "howpublished",
            "type",
            "pubstate",
            "chapter",
            "doi",
            "shorttitle",
            "subtitle",
            "language",
            "location",
            "url",
            "urldate",
            "pagetotal",
            "bookpagination",
            "note",
            "eprint",
            "eprintclass",
            "eprinttype",
            "origlanguage",
            "origlocation",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    collection: {
        order: 20,
        biblatex: "collection",
        csl: "dataset",
        required: ["editor", "title", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "chapter",
            "commentator",
            "doi",
            "edition",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "pages",
            "pagination",
            "pagetotal",
            "bookpagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volume",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    mvcollection: {
        order: 21,
        biblatex: "mvcollection",
        csl: "dataset",
        required: ["editor", "title", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "commentator",
            "doi",
            "edition",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "note",
            "number",
            "pagetotal",
            "bookpagination",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    incollection: {
        order: 22,
        biblatex: "incollection",
        csl: "chapter",
        required: ["title", "editor", "booktitle", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "booksubtitle",
            "booktitleaddon",
            "chapter",
            "commentator",
            "doi",
            "edition",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "pages",
            "pagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volume",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    suppcollection: {
        order: 23,
        biblatex: "suppcollection",
        csl: "chapter",
        required: ["title", "editor", "booktitle", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "booksubtitle",
            "booktitleaddon",
            "chapter",
            "commentator",
            "doi",
            "edition",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "pages",
            "pagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volume",
            "volumes",
            "origdate",
            "origlanguage",
            "annotation",
            "keywords",
        ],
    },
    post: {
        order: 30,
        biblatex: "online",
        csl: "post",
        required: ["date", "title", "url", "langid"],
        eitheror: ["editor", "author"],
        optional: [
            "abstract",
            "addendum",
            "pubstate",
            "subtitle",
            "shorttitle",
            "language",
            "urldate",
            "titleaddon",
            "version",
            "note",
            "organization",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    manual: {
        order: 40,
        biblatex: "manual",
        csl: "book",
        required: ["title", "date", "langid"],
        eitheror: ["editor", "author"],
        optional: [
            "abstract",
            "addendum",
            "chapter",
            "doi",
            "edition",
            "eprint",
            "eprintclass",
            "eprinttype",
            "isbn",
            "language",
            "location",
            "note",
            "number",
            "organization",
            "pages",
            "pagination",
            "pagetotal",
            "bookpagination",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "type",
            "url",
            "urldate",
            "version",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    misc: {
        order: 41,
        biblatex: "misc",
        csl: "article",
        required: ["title", "date", "langid"],
        eitheror: ["editor", "author"],
        optional: [
            "abstract",
            "addendum",
            "howpublished",
            "type",
            "pubstate",
            "organization",
            "doi",
            "shorttitle",
            "subtitle",
            "language",
            "location",
            "url",
            "urldate",
            "titleaddon",
            "version",
            "note",
            "eprint",
            "eprintclass",
            "eprinttype",
            "origlanguage",
            "origlocation",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    online: {
        order: 42,
        biblatex: "online",
        csl: "webpage",
        required: ["date", "title", "url", "langid"],
        eitheror: ["editor", "author"],
        optional: [
            "abstract",
            "addendum",
            "language",
            "note",
            "organization",
            "pubstate",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "urldate",
            "version",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    patent: {
        order: 43,
        biblatex: "patent",
        csl: "patent",
        required: ["title", "number", "author", "date"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "holder",
            "location",
            "pubstate",
            "doi",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "type",
            "url",
            "urldate",
            "version",
            "note",
            "eprint",
            "eprintclass",
            "eprinttype",
            "annotation",
            "keywords",
        ],
    },
    periodical: {
        order: 50,
        biblatex: "periodical",
        csl: "book",
        required: ["editor", "title", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "volume",
            "pubstate",
            "number",
            "series",
            "issn",
            "issue",
            "issuesubtitle",
            "issuetitle",
            "doi",
            "shorttitle",
            "subtitle",
            "editora",
            "editorb",
            "editorc",
            "url",
            "urldate",
            "language",
            "note",
            "eprint",
            "eprintclass",
            "eprinttype",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    suppperiodical: {
        order: 51,
        biblatex: "suppperiodical",
        csl: "article",
        required: ["journaltitle", "title", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "annotator",
            "commentator",
            "doi",
            "editor",
            "editora",
            "editorb",
            "editorc",
            "eid",
            "eprint",
            "eprintclass",
            "eprinttype",
            "issn",
            "issue",
            "issuesubtitle",
            "issuetitle",
            "journalsubtitle",
            "language",
            "note",
            "number",
            "pages",
            "pagination",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "version",
            "volume",
            "origdate",
            "origlanguage",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    proceedings: {
        order: 60,
        biblatex: "proceedings",
        csl: "book",
        required: ["editor", "title", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "chapter",
            "doi",
            "eprint",
            "eprintclass",
            "eprinttype",
            "eventdate",
            "eventtitle",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "organization",
            "pages",
            "pagination",
            "pagetotal",
            "bookpagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "url",
            "urldate",
            "venue",
            "volume",
            "volumes",
            "annotation",
            "keywords",
        ],
    },
    mvproceedings: {
        order: 61,
        biblatex: "mvproceedings",
        csl: "book",
        required: ["editor", "title", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "doi",
            "eprint",
            "eprintclass",
            "eprinttype",
            "eventdate",
            "eventtitle",
            "isbn",
            "language",
            "location",
            "note",
            "number",
            "organization",
            "pagetotal",
            "bookpagination",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "url",
            "urldate",
            "venue",
            "volumes",
            "annotation",
            "keywords",
        ],
    },
    inproceedings: {
        order: 62,
        biblatex: "inproceedings",
        csl: "paper-conference",
        required: ["title", "editor", "booktitle", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "booksubtitle",
            "booktitleaddon",
            "chapter",
            "doi",
            "eprint",
            "eprintclass",
            "eprinttype",
            "eventdate",
            "eventtitle",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "organization",
            "pages",
            "pagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "url",
            "urldate",
            "venue",
            "volume",
            "volumes",
            "annotation",
            "keywords",
        ],
    },
    reference: {
        order: 70,
        biblatex: "book",
        csl: "reference",
        required: ["editor", "title", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "chapter",
            "commentator",
            "doi",
            "edition",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "pages",
            "pagination",
            "pagetotal",
            "bookpagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volume",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    mvreference: {
        order: 71,
        biblatex: "mvreference",
        csl: "book",
        required: ["editor", "title", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "commentator",
            "doi",
            "edition",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "note",
            "number",
            "pagetotal",
            "bookpagination",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    inreference: {
        order: 72,
        biblatex: "inreference",
        csl: "entry-encyclopedia",
        required: ["title", "editor", "booktitle", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "booksubtitle",
            "booktitleaddon",
            "chapter",
            "commentator",
            "doi",
            "edition",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "pages",
            "pagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volume",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    "entry-encyclopedia": {
        order: 73,
        biblatex: "inreference",
        csl: "entry-encyclopedia",
        required: ["title", "editor", "booktitle", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "booksubtitle",
            "booktitleaddon",
            "chapter",
            "commentator",
            "doi",
            "edition",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "pages",
            "pagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volume",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    "entry-dictionary": {
        order: 74,
        biblatex: "inreference",
        csl: "entry-dictionary",
        required: ["title", "editor", "booktitle", "author", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "afterword",
            "annotator",
            "booksubtitle",
            "booktitleaddon",
            "chapter",
            "commentator",
            "doi",
            "edition",
            "editora",
            "editorb",
            "editorc",
            "eprint",
            "eprintclass",
            "eprinttype",
            "foreword",
            "introduction",
            "isbn",
            "language",
            "location",
            "mainsubtitle",
            "maintitle",
            "maintitleaddon",
            "note",
            "number",
            "pages",
            "pagination",
            "part",
            "publisher",
            "pubstate",
            "series",
            "shorttitle",
            "subtitle",
            "titleaddon",
            "translator",
            "url",
            "urldate",
            "volume",
            "volumes",
            "origdate",
            "origlanguage",
            "origlocation",
            "origpublisher",
            "origtitle",
            "annotation",
            "keywords",
        ],
    },
    report: {
        order: 80,
        biblatex: "report",
        csl: "report",
        required: ["author", "title", "type", "institution", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "pages",
            "pagination",
            "pagetotal",
            "bookpagination",
            "pubstate",
            "number",
            "isrn",
            "chapter",
            "doi",
            "shorttitle",
            "subtitle",
            "language",
            "location",
            "url",
            "urldate",
            "titleaddon",
            "version",
            "note",
            "eprint",
            "eprintclass",
            "eprinttype",
            "annotation",
            "keywords",
        ],
    },
    thesis: {
        order: 81,
        biblatex: "thesis",
        csl: "thesis",
        required: ["author", "title", "type", "institution", "date", "langid"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "pages",
            "pagination",
            "pagetotal",
            "bookpagination",
            "pubstate",
            "isbn",
            "chapter",
            "doi",
            "shorttitle",
            "subtitle",
            "language",
            "location",
            "url",
            "urldate",
            "titleaddon",
            "note",
            "eprint",
            "eprintclass",
            "eprinttype",
            "annotation",
            "keywords",
        ],
    },
    unpublished: {
        order: 90,
        biblatex: "unpublished",
        csl: "manuscript",
        required: ["title", "author", "date"],
        eitheror: [],
        optional: [
            "abstract",
            "addendum",
            "howpublished",
            "pubstate",
            "isbn",
            "date",
            "shorttitle",
            "subtitle",
            "language",
            "langid",
            "location",
            "url",
            "urldate",
            "titleaddon",
            "note",
            "annotation",
            "keywords",
        ],
    },
}
