// Copyright 2023 chenmingyong0423

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package templates

const GeneratedHeader = `// Generated by [optioner] command-line tool; DO NOT EDIT
// If you have any questions, please create issues and submit contributions at:
// https://github.com/chenmingyong0423/go-optioner

`

const AdditionalTemplateCode = `

type {{ .StructName }}Option{{if .GenericParams}}[{{range $index, $param := .GenericParams}}{{if $index}}, {{end}}{{$param.Name}} {{$param.Type}}{{end}}]{{end}} func(*{{ .StructName }}{{if .GenericParams}}[{{range $index, $param := .GenericParams}}{{if $index}}, {{end}}{{$param.Name}}{{end}}]{{end}})

func New{{ .StructName }}{{if .GenericParams}}[{{range $index, $param := .GenericParams}}{{if $index}}, {{end}}{{$param.Name}} {{$param.Type}}{{end}}]{{end}}({{ range $index, $field := .Fields }}{{ $field.Name | bigCamelToSmallCamel }} {{ $field.Type }},{{ end }} opts ...{{ .StructName }}Option{{if .GenericParams}}[{{range $index, $param := .GenericParams}}{{if $index}}, {{end}}{{$param.Name}}{{end}}]{{end}}) *{{ .StructName }}{{if .GenericParams}}[{{range $index, $param := .GenericParams}}{{if $index}}, {{end}}{{$param.Name}}{{end}}]{{end}} {
	{{ .NewStructName }} := &{{ .StructName }}{{if .GenericParams}}[{{range $index, $param := .GenericParams}}{{if $index}}, {{end}}{{$param.Name}}{{end}}]{{end}}{
		{{ range $index, $field := .Fields }}{{ $field.Name }}: {{ $field.Name | bigCamelToSmallCamel }},
		{{ end }}
	}

	for _, opt := range opts {
		opt({{ .NewStructName }})
	}

	return {{ .NewStructName }}
}

{{ if .OptionalFields }}
{{ range $field := .OptionalFields }}
func With{{ $.WithPrefix }}{{ $field.Name | capitalizeFirstLetter }}{{if $.GenericParams}}[{{range $index, $param := $.GenericParams}}{{if $index}}, {{end}}{{$param.Name}} {{$param.Type}}{{end}}]{{end}}({{ $field.Name | bigCamelToSmallCamel }} {{ $field.Type }}) {{ $.StructName }}Option{{if $.GenericParams}}[{{range $index, $param := $.GenericParams}}{{if $index}}, {{end}}{{$param.Name}}{{end}}]{{end}} {
	return func({{ $.NewStructName | bigCamelToSmallCamel }} *{{ $.StructName }}{{if $.GenericParams}}[{{range $index, $param := $.GenericParams}}{{if $index}}, {{end}}{{$param.Name}}{{end}}]{{end}}) {
		{{ $.NewStructName }}.{{ $field.Name }} = {{ $field.Name | bigCamelToSmallCamel }}
	}
}
{{ end }}
{{ end }}
`
