41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package generator
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/entity-maker/entity-maker/internal/naming"
|
|
)
|
|
|
|
// GenerateEnum generates the enum types file
|
|
func GenerateEnum(ctx *Context) (string, error) {
|
|
var b strings.Builder
|
|
|
|
// Imports
|
|
b.WriteString("from enum import StrEnum\n\n")
|
|
b.WriteString("from televend_core.databases.enum import EnumMixin\n\n\n")
|
|
|
|
// Generate each enum type
|
|
for _, enumType := range ctx.TableInfo.EnumTypes {
|
|
enumName := naming.ToPascalCase(enumType.TypeName)
|
|
|
|
b.WriteString(fmt.Sprintf("class %s(EnumMixin, StrEnum):\n", enumName))
|
|
|
|
if len(enumType.Values) == 0 {
|
|
b.WriteString(" pass\n")
|
|
} else {
|
|
for _, value := range enumType.Values {
|
|
// Convert value to valid Python identifier
|
|
// Usually enum values are already uppercase like "OPEN", "IN_PROGRESS"
|
|
identifier := strings.ToUpper(strings.ReplaceAll(value, " ", "_"))
|
|
identifier = strings.ReplaceAll(identifier, "-", "_")
|
|
|
|
b.WriteString(fmt.Sprintf(" %s = \"%s\"\n", identifier, value))
|
|
}
|
|
}
|
|
b.WriteString("\n")
|
|
}
|
|
|
|
return b.String(), nil
|
|
}
|