package main

import (
	"fmt"

	"github.com/brianvoe/gofakeit/v7"
)

// User demonstrates struct generation
type User struct {
	ID        int    `fake:"{number:1,1000}"`
	FirstName string `fake:"{firstname}"`
	LastName  string `fake:"{lastname}"`
	Email     string `fake:"{email}"`
	Phone     string `fake:"{phone}"`
	Age       int    `fake:"{number:18,80}"`
	Active    bool   `fake:"{bool}"`
}

// Address demonstrates nested struct generation
type Address struct {
	Street  string `fake:"{street}"`
	City    string `fake:"{city}"`
	State   string `fake:"{state}"`
	Zip     string `fake:"{zip}"`
	Country string `fake:"{country}"`
}

func main() {
	// Set seed for reproducible results (optional)
	gofakeit.Seed(12345)

	// Basic generators
	fmt.Println("Name:", gofakeit.Name())
	fmt.Println("Email:", gofakeit.Email())
	fmt.Println("Phone:", gofakeit.Phone())
	fmt.Println("Address:", gofakeit.Address().Address)

	// Numbers and booleans
	fmt.Println("Int (1-100):", gofakeit.IntRange(1, 100))
	fmt.Println("Float:", gofakeit.Float64Range(0, 100))
	fmt.Println("Bool:", gofakeit.Bool())

	// Dates and times
	fmt.Println("Date:", gofakeit.Date())
	fmt.Println("FutureDate:", gofakeit.FutureDate())
	fmt.Println("PastDate:", gofakeit.PastDate())

	// Internet and identifiers
	fmt.Println("URL:", gofakeit.URL())
	fmt.Println("IPv4:", gofakeit.IPv4Address())
	fmt.Println("UUID:", gofakeit.UUID())
	fmt.Println("Username:", gofakeit.Username())
	fmt.Println("Password:", gofakeit.Password(true, true, true, true, false, 16))

	// Business data
	fmt.Println("Company:", gofakeit.Company())
	fmt.Println("Job Title:", gofakeit.JobTitle())
	fmt.Println("Credit Card:", gofakeit.CreditCardNumber(nil))

	// Generate entire struct with fake tags
	var user User
	gofakeit.Struct(&user)
	fmt.Printf("\nGenerated User: %+v\n", user)

	// Generate slice of structs
	var users []User
	gofakeit.Slice(&users)
	fmt.Printf("Generated %d users\n", len(users))

	// Slice with custom length
	users = make([]User, 5)
	for i := range users {
		gofakeit.Struct(&users[i])
	}
	fmt.Printf("Generated %d users (fixed size)\n", len(users))

	// Random selection from slice
	colors := []string{"red", "green", "blue", "yellow"}
	color := gofakeit.RandomString(colors)
	fmt.Println("Random color:", color)

	// Weighted random
	weighted := gofakeit.Weighted(
		[]any{"common", "uncommon", "rare"},
		[]float32{0.7, 0.2, 0.1},
	)
	fmt.Println("Weighted:", weighted)

	// Generate Lorem Ipsum
	fmt.Println("Sentence:", gofakeit.Sentence(10))
	fmt.Println("Paragraph:", gofakeit.Paragraph(1, 3, 5, " "))

	// JSON generation
	json, _ := gofakeit.JSON(&gofakeit.JSONOptions{
		Type: "object",
		Fields: []gofakeit.Field{
			{Name: "id", Function: "uuid"},
			{Name: "name", Function: "name"},
			{Name: "email", Function: "email"},
		},
	})
	fmt.Println("JSON:", string(json))

	// Custom faker for thread-safety
	faker := gofakeit.New(0)
	fmt.Println("Thread-safe name:", faker.Name())
}
