
// mySettings provides functions to access a user's settings

package mySettings

import "seekia/internal/myDatastores/myMap"

import "errors"

var mySettingsMapDatastore *myMap.MyMap

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

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

	mySettingsMapDatastore = newMySettingsMapDatastore

	return nil
}

//Outputs:
//	-bool: Setting exists
//	-string: Setting value
//	-error
func GetSetting(settingName string) (bool, string, error){

	if (settingName == ""){
		return false, "", errors.New("GetSetting called with empty settingName.")
	}

	exists, settingString, err := mySettingsMapDatastore.GetMapEntry(settingName)
	if (err != nil) { return false, "", err }
	if (exists == false){
		return false, "", nil
	}

	return true, settingString, nil
}

func SetSetting(settingName string, content string)error{

	if (settingName == ""){
		return errors.New("SetSetting called with empty SettingName.")
	}
	if (content == ""){
		return errors.New("SetSetting called with empty content.")
	}

	err := mySettingsMapDatastore.SetMapEntry(settingName, content)
	if (err != nil){ return err }	

	return nil
}

func DeleteSetting(settingName string)error{

	if (settingName == ""){
		return errors.New("DeleteSetting called with empty SettingName.")
	}

	err := mySettingsMapDatastore.DeleteMapEntry(settingName)
	if (err != nil) { return err }

	return nil
}



