{{/* The line below tells Intellij/GoLand to enable the autocompletion based *gen.Type type. */}}
{{/* gotype: entgo.io/ent/entc/gen.Type */}}

{{ define "model/stringer" }}
    {{- if eq $.Name "Pet" }}
        // custom stringer implementation (in this case none)
    {{ else }}
        {{ $receiver := $.Receiver }}
        // String implements the fmt.Stringer.
        func ({{ $receiver }} *{{ $.Name }}) String() string {
            var builder strings.Builder
            builder.WriteString("{{ $.Name }}(")
            builder.WriteString(fmt.Sprintf("id=%v", {{ $receiver }}.ID))
            {{- range $i, $f := $.Fields }}
                {{- if $f.Sensitive }}
                    builder.WriteString(", {{ $f.Name }}=<sensitive>")
                {{- else }}
                    {{- $sf := printf "%s.%s" $receiver $f.StructField }}
                    {{- if $f.Nillable }}
                        if v := {{ $sf }}; v != nil {
                            builder.WriteString(", {{ $f.Name }}=")
                            {{- if and $f.IsTime (not $f.HasGoType) }}
                                builder.WriteString(v.Format(time.ANSIC))
                            {{- else if and $f.IsString (not $f.HasGoType) }}
                                builder.WriteString(*v)
                            {{- else }}
                                builder.WriteString(fmt.Sprintf("%v", *v))
                            {{- end }}
                        }
                    {{- else }}
                        builder.WriteString(", {{ $f.Name }}=")
                        {{- if and $f.IsTime (not $f.HasGoType) }}
                            builder.WriteString({{ $sf }}.Format(time.ANSIC))
                        {{- else if and $f.IsString (not $f.HasGoType) }}
                            builder.WriteString({{ $sf }})
                        {{- else }}
                            builder.WriteString(fmt.Sprintf("%v", {{ $sf }}))
                        {{- end }}
                    {{- end }}
                {{- end }}
            {{- end }}
            builder.WriteByte(')')
            return builder.String()
        }
    {{- end}}
{{ end }}
