func NewPartialGenerator(st *jen.Statement) *PartialGenerator {
	if st != nil {
		return &PartialGenerator{
			raw: st,
		}
	}
	return &PartialGenerator{
		raw: &jen.Statement{},
	}
}
NewPartialGenerator returns a partial generator
package generator
import (
	"fmt"
	"go/ast"
	ps "go/parser"
	"go/token"
	"strings"
	"strconv"
	"bytes"
	"go/format"
	"github.com/dave/jennifer/jen"
	"github.com/kujtimiihoxha/kit/fs"
	"github.com/kujtimiihoxha/kit/parser"
	"github.com/kujtimiihoxha/kit/utils"
	"github.com/sirupsen/logrus"
)
type Gen interface {
	Generate() error
}
type BaseGenerator struct {
	srcFile *jen.File
	code    *PartialGenerator
	fs      *fs.KitFs
}
func (b *BaseGenerator) InitPg() {
	b.code = NewPartialGenerator(b.srcFile.Empty())
}
func (b *BaseGenerator) getMissingImports(imp []parser.NamedTypeValue, f *parser.File) ([]parser.NamedTypeValue, error) {
	n := []parser.NamedTypeValue{}
	for _, v := range imp {
		for i, vo := range f.Imports {
			if vo.Name == "" {
				tp, err := strconv.Unquote(vo.Type)
				if err != nil {
					return n, err
				}
				if v.Type == vo.Type && strings.HasSuffix(tp, v.Name) {
					break
				}
			}
			if v.Type == vo.Type && v.Name == vo.Name {
				break
			} else if i == len(f.Imports)-1 {
				n = append(n, v)
			}
		}
	}
	if len(f.Imports) == 0 {
		n = imp
	}
	return n, nil
}
func (b *BaseGenerator) CreateFolderStructure(path string) error {
	e, err := b.fs.Exists(path)
	if err != nil {
		return err
	}
	if !e {
		logrus.Debug(fmt.Sprintf("Creating missing folder structure : %s", path))
		return b.fs.MkdirAll(path)
	}
	return nil
}
func (b *BaseGenerator) GenerateNameBySample(sample string, exclude []parser.NamedTypeValue) string {
	sn := 1
	name := utils.ToLowerFirstCamelCase(sample)[:sn]
	for _, v := range exclude {
		if v.Name == name {
			sn++
			if sn > len(sample) {
				sample = string(len(sample) - sn)
			}
			name = utils.ToLowerFirstCamelCase(sample)[:sn]
		}
	}
	return name
}
func (b *BaseGenerator) EnsureThatWeUseQualifierIfNeeded(tp string, imp []parser.NamedTypeValue) string {
	if bytes.HasPrefix([]byte(tp), []byte("...")) {
		return ""
	}
	if t := strings.Split(tp, "."); len(t) > 0 {
		s := t[0]
		for _, v := range imp {
			i, _ := strconv.Unquote(v.Type)
			if strings.HasSuffix(i, s) || v.Name == s {
				return i
			}
		}
		return ""
	}
	return ""
}
func (b *BaseGenerator) AddImportsToFile(imp []parser.NamedTypeValue, src string) (string, error) {
	fset := token.NewFileSet()
	f, err := ps.ParseFile(fset, "", src, 0)
	if err != nil {
		return "", err
	}
	found := false
	for i := 0; i < len(f.Decls); i++ {
		d := f.Decls[i]
		switch d.(type) {
		case *ast.FuncDecl:
		case *ast.GenDecl:
			dd := d.(*ast.GenDecl)
			if dd.Tok == token.IMPORT {
				if dd.Rparen == 0 || dd.Lparen == 0 {
					dd.Rparen = f.Package
					dd.Lparen = f.Package
				}
				found = true
				for _, v := range imp {
					iSpec := &ast.ImportSpec{
						Name: &ast.Ident{Name: v.Name},
						Path: &ast.BasicLit{Value: v.Type},
					}
					dd.Specs = append(dd.Specs, iSpec)
				}
			}
		}
	}
	if !found {
		dd := ast.GenDecl{
			TokPos: f.Package + 1,
			Tok:    token.IMPORT,
			Specs:  []ast.Spec{},
			Lparen: f.Package,
			Rparen: f.Package,
		}
		lastPos := 0
		for _, v := range imp {
			lastPos += len(v.Name) + len(v.Type) + 1
			iSpec := &ast.ImportSpec{
				Name:   &ast.Ident{Name: v.Name},
				Path:   &ast.BasicLit{Value: v.Type},
				EndPos: token.Pos(lastPos),
			}
			dd.Specs = append(dd.Specs, iSpec)
		}
		f.Decls = append([]ast.Decl{&dd}, f.Decls...)
	}
	ast.SortImports(fset, f)
	var buf bytes.Buffer
	if err := format.Node(&buf, fset, f); err != nil {
		return "", err
	}
	return fmt.Sprintf("%s", buf.Bytes()), nil
}
type PartialGenerator struct {
	raw *jen.Statement
}