package generate_test

import "seekia/internal/generate"

import "seekia/internal/genetics/geneticReferences/traits"
import "seekia/internal/genetics/geneticReferences/monogenicDiseases"
import "seekia/internal/genetics/geneticReferences/polygenicDiseases"
import "seekia/internal/helpers"
import "seekia/internal/identity"
import "seekia/internal/messaging/readMessages"
import "seekia/internal/parameters/readParameters"
import "seekia/internal/profiles/profileFormat"

import "testing"


func TestGenerateParameters(t *testing.T){

	parametersTypesList := readParameters.GetAllParametersTypesList()

	for _, parametersType := range parametersTypesList{

		networkType, err := helpers.GetRandomByteWithinRange(1, 2)
		if (err != nil) {
			t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
		}

		_, err = generate.GetFakeParameters(parametersType, networkType)
		if (err != nil) {
			t.Fatal("Failed to get fake parameters: " + err.Error())
		}
	}
}


func TestGenerateProfiles(t *testing.T){

	monogenicDiseases.InitializeMonogenicDiseaseVariables()

	err := polygenicDiseases.InitializePolygenicDiseaseVariables()
	if (err != nil) {
		t.Fatal("InitializePolygenicDiseaseVariables failed: " + err.Error())
	}

	err = traits.InitializeTraitVariables()
	if (err != nil) {
		t.Fatal("InitializeTraitVariables failed: " + err.Error())
	}

	err = profileFormat.InitializeProfileFormatVariables()
	if (err != nil) {
		t.Fatal("Failed to initialize profile format variables: " + err.Error())
	}

	newIdentityPublicKey, newIdentityPrivateKey, err := identity.GetNewRandomPublicPrivateIdentityKeys()
	if (err != nil) {
		t.Fatal("Cannot get random identity keys: " + err.Error())
	}

	for i:=0; i < 20; i++{

		networkType, err := helpers.GetRandomByteWithinRange(1, 2)
		if (err != nil) {
			t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
		}

		_, err = generate.GetFakeProfile("Mate", newIdentityPublicKey, newIdentityPrivateKey, networkType)
		if (err != nil) {
			t.Fatal("Cannot create fake mate profile: " + err.Error())
		}
	}

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	_, err = generate.GetFakeProfile("Host", newIdentityPublicKey, newIdentityPrivateKey, networkType)
	if (err != nil) {
		t.Fatal("Cannot create fake host profile: " + err.Error())
	}

	_, err = generate.GetFakeProfile("Moderator", newIdentityPublicKey, newIdentityPrivateKey, networkType)
	if (err != nil) {
		t.Fatal("Cannot create fake moderator profile: " + err.Error())
	}
}

func TestGenerateReviews(t *testing.T){

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	_, err = generate.GetFakeReview("Identity", networkType)
	if (err != nil){
		t.Fatal("Cannot create fake Identity review: " + err.Error())
	}
	_, err = generate.GetFakeReview("Profile", networkType)
	if (err != nil){
		t.Fatal("Cannot create fake Profile review: " + err.Error())
	}
	_, err = generate.GetFakeReview("Attribute", networkType)
	if (err != nil){
		t.Fatal("Cannot create fake Attribute review: " + err.Error())
	}
	_, err = generate.GetFakeReview("Message", networkType)
	if (err != nil){
		t.Fatal("Cannot create fake Message review: " + err.Error())
	}

}

func TestGenerateReports(t *testing.T){

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	_, err = generate.GetFakeReport("Identity", networkType)
	if (err != nil){
		t.Fatal("Cannot create fake Identity report: " + err.Error())
	}
	_, err = generate.GetFakeReport("Profile", networkType)
	if (err != nil){
		t.Fatal("Cannot create fake Profile report: " + err.Error())
	}
	_, err = generate.GetFakeReport("Attribute", networkType)
	if (err != nil){
		t.Fatal("Cannot create fake Attribute report: " + err.Error())
	}
	_, err = generate.GetFakeReport("Message", networkType)
	if (err != nil){
		t.Fatal("Cannot create fake Message report: " + err.Error())
	}
}

func TestGenerateMessages(t *testing.T){

	networkType, err := helpers.GetRandomByteWithinRange(1, 2)
	if (err != nil) {
		t.Fatal("GetRandomByteWithinRange failed: " + err.Error())
	}

	{

		messageBytes, _, messageCipherKey, err := generate.GetFakeMessage(networkType, "Text")
		if (err != nil){
			t.Fatal("Cannot create fake text message: " + err.Error())
		}

		ableToRead, _, _, _, _, _, err := readMessages.ReadChatMessageWithCipherKey(messageBytes, messageCipherKey)
		if (err != nil){
			t.Fatal("Failed to read generated text message: " + err.Error())
		}
		if (ableToRead == false){
			t.Fatal("Failed to read generated text message: Invalid result.")
		}
	}

	{
		messageBytes, _, messageCipherKey, err := generate.GetFakeMessage(networkType, "Image")
		if (err != nil){
			t.Fatal("Cannot create fake image message: " + err.Error())
		}

		ableToRead, _, _, networkType_Received, _, _, err := readMessages.ReadChatMessageWithCipherKey(messageBytes, messageCipherKey)
		if (err != nil){
			t.Fatal("Failed to read generated image message: " + err.Error())
		}
		if (ableToRead == false){
			t.Fatal("Failed to read generated image message: Invalid result.")
		}
		if (networkType != networkType_Received){
			t.Fatal("Generated image message network type does not match.")
		}
	}
}






