package apigen

import "git.qianqiusoft.com/qianqiusoft/light-apiengine-client/code_gen/utils"

const vueTemplate = `
import axios from '../../axios'

{{$dataName := .data.Name}}
{{range .data.Apis}}
{{if Contains .Method "get" -}}
// @brief {{.Desc}}
export const {{CamelizeStr .Name true}} = (data) => {
	let url = 'api/v1/{{$dataName}}/{{.Name}}?'
    for (var key in data) {
		url += key + '=' + data[key] + '&'
    }
	return axios({
		url: url,
		method: 'get'
    })
}
{{else if Contains .Method "post" -}}
// @brief {{.Desc}}
export const {{CamelizeStr .Name true}} = (data) => {
	let url = 'api/v1/{{$dataName}}/{{.Name}}'
	return axios({
		url: url,
		method: 'post',
		data
    })
}
{{end -}}
{{- end}}
`

func GenVue(templateData interface{}, params map[string]interface{}) ([]byte, error) {
	return utils.GenTemplate(vueTemplate, templateData, params)
}
