
// myLocalProfiles provides functions to store and access a user's local Mate, Host, and Moderator profiles.
// A local profile is a map of Attribute Name -> Attribute Value, stored within a myMap datastore.
// Some of these attributes are special, and define how the profile will be created.
// See myProfileExports.go to see how a profile is exported.
// To access broadcasted profiles, use myBroadcasts.go.

package myLocalProfiles

import "seekia/internal/myDatastores/myMap"

import "errors"

var myMateProfileMapDatastore *myMap.MyMap
var myHostProfileMapDatastore *myMap.MyMap
var myModeratorProfileMapDatastore *myMap.MyMap

// This function must be called whenever we sign in to an app user
func InitializeMyLocalProfileDatastores()error{

	newMateProfileMapDatastore, err := myMap.CreateNewMap("MyLocalMateProfile")
	if (err != nil) { return err }

	newHostProfileMapDatastore, err := myMap.CreateNewMap("MyLocalHostProfile")
	if (err != nil) { return err }

	newModeratorProfileMapDatastore, err := myMap.CreateNewMap("MyLocalModeratorProfile")
	if (err != nil) { return err }

	myMateProfileMapDatastore = newMateProfileMapDatastore
	myHostProfileMapDatastore = newHostProfileMapDatastore
	myModeratorProfileMapDatastore = newModeratorProfileMapDatastore

	return nil
}

func SetProfileData(profileType string, attributeName string, content string)error{

	if (attributeName == ""){
		return errors.New("SetProfileData called with empty attribute.")
	}

	if (content == ""){
		return errors.New("SetProfileData called with empty content for attribute: " + attributeName)
	}

	if (profileType == "Mate"){
		err := myMateProfileMapDatastore.SetMapEntry(attributeName, content)
		if (err != nil) { return err }

		return nil
	}
	if (profileType == "Host"){
		err := myHostProfileMapDatastore.SetMapEntry(attributeName, content)
		if (err != nil) { return err }

		return nil
	}
	if (profileType == "Moderator"){
		err := myModeratorProfileMapDatastore.SetMapEntry(attributeName, content)
		if (err != nil) { return err }

		return nil
	}

	return errors.New("SetProfileData called with invalid profile type: " + profileType)
}

//Outputs:
//	-bool: Attribute exists
//	-string: Profile attribute data
//	-error
func GetProfileData(profileType string, attributeName string)(bool, string, error){

	if (attributeName == ""){
		return false, "", errors.New("GetProfileData called with empty attribute.")
	}

	if (profileType == "Mate"){
		exists, value, err := myMateProfileMapDatastore.GetMapEntry(attributeName)
		if (err != nil) { return false, "", err }
		if (exists == false){
			return false, "", nil
		}

		return true, value, nil
	}
	if (profileType == "Host"){
		exists, value, err := myHostProfileMapDatastore.GetMapEntry(attributeName)
		if (err != nil) { return false, "", err }
		if (exists == false){
			return false, "", nil
		}

		return true, value, nil
	}
	if (profileType == "Moderator"){
		exists, value, err := myModeratorProfileMapDatastore.GetMapEntry(attributeName)
		if (err != nil) { return false, "", err }
		if (exists == false){
			return false, "", nil
		}

		return true, value, nil
	}

	return false, "", errors.New("GetProfileData called with invalid profile type: " + profileType)
}


func DeleteProfileData(profileType string, attributeName string)error{

	if (attributeName == ""){
		return errors.New("DeleteProfileData called with empty attributeName.")
	}

	if (profileType == "Mate"){
		err := myMateProfileMapDatastore.DeleteMapEntry(attributeName)
		if (err != nil) { return err }

		return nil
	}
	if (profileType == "Host"){
		err := myHostProfileMapDatastore.DeleteMapEntry(attributeName)
		if (err != nil) { return err }

		return nil
	}
	if (profileType == "Moderator"){
		err := myModeratorProfileMapDatastore.DeleteMapEntry(attributeName)
		if (err != nil) { return err }

		return nil
	}

	return errors.New("DeleteProfileData called with invalid profile type: " + profileType)
}




