--luacheck: ignore 212 111
---@diagnostic disable: missing-return, lowercase-global
---@class {{.ClassName}}{{if ne .Inheritance ""}} : {{.Inheritance}}{{end}}
{{- range .Fields}}
---@field {{.Name}} {{.Type}}{{if ne .Comment ""}} {{.Comment}}{{end}}
{{- end}}
{{.ClassName}} = {
    {{- $n := len .Methods}}
    {{- range $index, $method := .Methods}}
    ---@param self {{$.ClassName}}
    {{- range $param := $method.Params}}
    ---@param {{.Name}} {{.Type}}{{if ne .Comment ""}} {{.Comment}}{{end}}
    {{- end}}
    {{- if gt (len $method.Returns) 0}}
    {{- range $retIndex, $ret := $method.Returns}}
    {{- if eq $retIndex (sub (len $method.Returns) 1)}}
    ---@return {{.Type}}{{if ne .Comment ""}} #{{truncateComment .Comment 80}}{{end}}
    {{- else}}
    ---@return {{.Type}}{{if ne .Comment ""}} #{{truncateComment .Comment 80}}{{end}}
    {{- end}}
    {{- end}}
    {{.Name}} = function(self{{if gt (len .Params) 0}}, {{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}{{end}}{{end}}) end,{{if ne $method.Comment ""}} -- {{truncateComment $method.Comment 80}}{{end}}
    {{- else}}
    {{.Name}} = function(self{{if gt (len .Params) 0}}, {{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}{{end}}{{end}}) end,{{if ne $method.Comment ""}} -- {{truncateComment $method.Comment 80}}{{end}}
    {{- end}}
    {{- if ne (plus1 $index) $n}}

    {{- end}}
{{- end}}
}

{{- if gt (len .Constructors) 0}}
---@type {{$.ClassName}}
{{- range .Constructors}}
---@overload fun({{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}: {{$param.Type}}{{end}}): {{$.ClassName}}
{{- end}}
{{- end}}
{{.ClassName}} = nil
-- Define class globally so it's "available" to other files