package data

import (
	"math/rand"
	"time"

	"go.buzzert.net/kordophone-mock/model"
	"github.com/google/uuid"
)

var generatedNameIdx = 0

func GenerateRandomName() string {
	// From:
	// https://docs.google.com/spreadsheets/d/1KOP4mNAX5R0N_dODE6j2gHTK2oTXCIrhAQ0dEniaYFw/htmlview
	names := []string{
		"Kevin Faite",
		"Luis Kundley",
		"Derrick Powell",
		"Bret Kanders",
		"Wil Norton",
		"Jody Storker",
		"Brad Klark",
		"Kirt Magnozzi",
		"Howard Dass",
		"Jim Dallach",
		"Dave Glark",
		"Brian Silkins",
		"Barry Lesttade",
		"Andres Fretcher",
		"Mark McLee",
		"Doug Iaflate",
		"Luke Vrisebois",
		"Ronnis Pawgood",
		"Rob Maigle",
		"Martin Licci",
		"Allan Chantz",
		"Dave Cozlov",
		"Yan Vaumgat",
		"Luis Khura",
		"Paul Caramnov",
		"Kevin Mumminen",
		"Glen Perner",
		"Ricky Sitov",
		"Oleg Veers",
		"Jeff Nurray",
		"Mark Smoth",
		"Walt Gliver",
		"Larry Nayes",
		"Mike Truk",
		"Paul Ling",
		"Wil Gefferies",
		"Jeff Enthony",
		"John Riazzu",
		"Andy Clantire",
		"Damon Handberg",
		"Kevin Shekield",
		"Dante Elou",
		"Ray Ponda",
		"Randy Chaw",
		"Mike Lonan",
		"Mac Baglianeti",
		"Tony Smehrik",
		"Tim Biset",
		"Garry Gubinsky",
		"Tom Dorefer",
		"Al Endrey",
		"Randy Clatt",
		"Joey Full",
		"Peter Telanne",
		"Al McSteen",
		"Pat Leichel",
		"Phil Felik",
		"Eddie Dallagher",
		"Sammy Nereker",
		"Rich Kamuel",
		"Brian Goung",
		"Jose Norandir",
		"Tony Ban Slyke",
		"Darren Jilkey",
		"Eddie Lagwell",
		"Lenny Gutler",
		"Jay Butierrez",
		"Terry Omith",
		"Juan Matal",
		"Franco Riddall",
		"Luis Klayton",
		"Troy Hugles",
		"Sandis Ceane",
		"Ken Nurphy",
		"Alex Turzeon",
		"Tomas Lakid",
		"Andre Tackett",
		"Jesse Kurimeau",
		"Derek Artwood",
		"Bill Nay",
		"Jack Dozon",
		"Randy Reblan",
		"Dave Sweemey",
		"Greg Bernon",
		"Sho Nironov",
		"Andujar Ersulak",
		"Sleve McDichael",
		"Benito Labo",
		"Moises Jirardi",
		"Eric Pollins",
		"Derek Plaught",
		"Willie Whisen",
		"Joe Sedeno",
		"Darren Sryper",
		"Kevin Ousmus",
		"Fran Rosa",
		"Chris Leiss",
		"Joe Derry",
		"Todd Willicams",
		"Mark Lourque",
		"Birry Odereitt",
		"James Pasek",
		"Jari Nuni",
		"Pavel Thidault",
		"Dave Quitter",
		"Mike Johnton",
		"Steve Gizel",
		"Tom Iklund",
		"Brian Niller",
		"Steve Lorsato",
		"Don Poulder",
		"Secil Tisio",
		"Ed Rario",
		"Kevin Rohnson",
		"Jose Every",
		"Orestes Narkin",
		"Mike Genarides",
		"Rick Buncan",
		"Ricky Nerced",
		"Barry Rankford",
		"Dave Laubensee",
		"Kevin Leed",
		"Orlando Dwynn",
		"Mark Brace",
		"Joe Ryden",
		"Alex Ralker",
		"Tom Menwaring",
		"Steven Czerpaws",
		"Scott Balgneault",
		"Al Puhr",
		"Marty Basin",
		"Bret Gutter",
		"Jason Doulet",
		"Jeff Eivazoff",
		"David Zilmour",
		"Bobby Levason",
		"Glen Phanahan",
		"Pat Channon",
		"Patrick Lanford",
		"Danny Mylander",
		"Jemus Erde",
		"Eric Pent",
		"Sleve Redrosian",
		"Henry Lelly",
		"Darrin Clerk",
		"Henry Ancaviglia",
		"Tim Foung",
		"Royce Elicea",
		"Ryan Ginley",
		"Dave Carros",
		"Carlos Drown",
		"Sib Luechele",
		"Bip Karr",
		"Charlie Tansing",
		"Ozzie Thompsen",
		"Bobby Krarsa",
		"Kevin Bogarty",
		"Sandy Grown",
		"John Laporest",
		"Jose Pundin",
		"Mark Loenick",
		"Bill Prodert",
		"Dave Kullen",
		"Claude McShee",
		"Stephane Brok",
		"Keith McVean",
		"Ray Bill",
		"Jonasan Fidd",
		"Brian Elesson",
		"Steve Thompton",
		"Dwight Blavine",
		"Jeff Norris",
		"Delino Jole",
		"Tim Oisenreich",
		"Jarvis Fell",
		"Robby Smoth",
		"Vince Liggio",
		"Mickey Ofterman",
		"Jeff Dell",
		"Ave Bizcaino",
		"Bobby Kotto",
		"Eric Drissom",
		"Bernard Rewis",
		"Bill Putanton",
		"Shawn Setrov",
		"Wes Lamsey",
		"Warren Goucher",
		"Sala Bineen",
		"Dimitri Ysedaert",
		"Biry Dedorov",
		"Elvis Crushel",
		"Mike Zilchrist",
		"Mike McLae",
		"Craig Channon",
		"Paul Williarms",
		"Emitri Nore",
		"Mike Lichardson",
		"Craig Goleman",
		"Ryne Smith",
		"Chuck Goberts",
		"John Malarraga",
		"Brett Dokstra",
		"Archi Nartin",
		"Matt Beile",
		"Bobby Raminiti",
		"Pele Lodriguez",
		"Don Gianfrocc",
		"Greg Lay",
		"Reggie Lenteria",
		"Jerald Kordero",
		"Gregg Klark",
		"Tim Donato",
		"Tom Vellows",
		"Brad Bennings",
		"Jan Svobota",
		"Jacky Milmanov",
		"Josef Lelfour",
		"Andrey Vurr",
		"Roman Klark",
		"Valeri Varr",
		"Steve Nackey",
		"Todd Romi",
		"Ted Brimson",
		"Mike Lathja",
	}

	name := names[generatedNameIdx%len(names)]
	generatedNameIdx = generatedNameIdx + 1
	return name
}

func GenerateRandomMessageBody() string {
	// Generated by GPT-4
	messages := []string{
		"Good morning! How are you?",
		"What's the plan for today?",
		"Wanna grab lunch later?",
		"Did you finish the assignment?",
		"How did the interview go?",
		"Just left the gym, feeling great!",
		"What time is the party tonight?",
		"Can you pick up some groceries on your way home?",
		"Remember to call mom for her birthday!",
		"Do you know what the homework was?",
		"I'm stuck in traffic, sorry I'll be late.",
		"How was your weekend?",
		"I can't believe it's Monday already.",
		"Did you catch the game last night?",
		"Wanna see a movie Friday night?",
		"Just saw someone with the weirdest shirt!",
		"I miss hanging out with you!",
		"Do you remember where I left my keys?",
		"Quick question: cats or dogs?",
		"When does your flight arrive?",
		"I'm about to board the plane, see you soon!",
		"I passed the exam! We should celebrate!",
		"Did you hear the news?",
		"Goodnight!",
		"I made it home safely, thanks for tonight.",
		"What's your opinion on pineapple on pizza?",
		"I can't find my wallet, can you check if I left it at your place?",
		"Text me when you get here.",
		"I found the perfect gift for Sarah!",
		"Do you want to join me for a coffee later?",
		"I'm almost there, sorry I'm running late!",
		"I've got the newest season of our favorite show, want to binge-watch tonight?",
		"I'm having a rough day, can we talk later?",
		"What should I wear to the event?",
		"I'm lost, can you send me the address again?",
		"How's your day going?",
		"Guess what just happened!",
		"I think I'm coming down with a cold.",
		"Did you book the tickets for the concert?",
		"Just heard our song on the radio!",
		"Save me a seat in class?",
		"Could you cover my shift today?",
		"Parents just surprised me with a visit!",
		"I got the job!",
		"Bring an umbrella, it's pouring outside!",
		"Do you still have that book I lent you?",
		"I've been thinking about you all day.",
		"When are you free this week?",
		"The cake you made was delicious!",
		"I can't stop laughing at that joke you told me.",
		"Did you send the email?",
		"What's your favorite emoji?",
		"I just bought the cutest outfit!",
		"Remember when we went camping last summer?",
		"I can't find my headphones, have you seen them?",
		"What time is the dentist appointment?",
		"I forgot my charger, can I borrow yours?",
		"Let's plan a trip together someday!",
		"I love the photos from last night!",
		"Guess who I just bumped into?",
		"How's your family doing?",
		"Have you finished the book you were reading?",
		"Want to try a new recipe with me?",
		"Let's go for a run tomorrow morning?",
		"I'm craving Chinese food, any recommendations?",
		"I'm exhausted, it's been a long day.",
		"Looking forward to our date tonight.",
		"Best coffee you've ever had?",
		"I should have brought a jacket, it's freezing!",
		"Did you change your hair?",
		"Who do you think will win the election?",
		"Can you believe we're graduating soon?",
		"Any plans for the weekend?",
		"I'm so hungry, what's for dinner?",
		"The baby finally fell asleep.",
		"Have you started the new series on Netflix?",
		"I love your new profile picture!",
		"How's the new job going?",
	}

	return messages[rand.Intn(len(messages))]
}

func GenerateRandomConversation() model.Conversation {
	conversation := model.Conversation{
		Participants: []string{GenerateRandomName()},
		UnreadCount:  0,
		Guid:         uuid.New().String(),
		Date:         model.Date(time.Now().Add(-1 * time.Duration(rand.Intn(1000000)) * time.Second)),
	}

	return conversation
}

func randomParticipant(participants []string) *string {
	if len(participants) == 1 {
		if rand.Intn(2) == 0 {
			return &participants[0]
		}
	}

	if rand.Intn(2) == 0 {
		// From me
		return nil
	}

	return &participants[rand.Intn(len(participants))]
}

func GenerateRandomMessage(participants []string) model.Message {
	sender := randomParticipant(participants)

	return model.Message{
		Text:   GenerateRandomMessageBody(),
		Guid:   uuid.NewString(),
		Date:   model.Date(time.Now().Add(-1 * time.Duration(rand.Intn(1000000)) * time.Second)),
		Sender: sender,
	}
}

func GenerateAttachmentMessage(participants []string, attachmentGuid string) model.Message {
	sender := randomParticipant(participants)
	return model.Message{
		Text:            "", // todo: try using attachment character here?
		Guid:            uuid.NewString(),
		Date:            model.Date(time.Now().Add(-1 * time.Duration(rand.Intn(1000000)) * time.Second)),
		Sender:          sender,
		AttachmentGUIDs: []string{attachmentGuid},
	}
}
