package public

//
//
// msg env ////////////////////////////////////////////////////////////////
//

const EndSign							byte    = 125
const msgerror							string = "error"


// msg type ////////////////////////////////////////////////////////////////

const Msg_Report						string = "report"
const Msg_Exec							string = "exec"
const Msg_Backup						string = "backup"
const Msg_Reg							string = "reg"
const Msg_Error							string = "error"


// base word ////////////////////////////////////////////////////////////////
const LogInUser							string = "LogInUser"
const LogOutUser						string = "LogOutUser"
const WillLogInUser						string = "WillLogInUser"
const WillLogOutUser					string = "WillLogOutUser"
const TurnOnPC							string = "TurnOnPC"
const TurnOffPC							string = "TurnOffPC"
const WillTurnOnPC						string = "WillTurnOnPC"
const WillTurnOffPC						string = "WillTurnOffPC"

// msg report type ///////////////////////////////////////////////////////////

const Msg_Report_LoginInUser			string = LogInUser
const Msg_Report_LogOutUser				string = LogInUser
const Msg_Report_WillLogInUser			string = WillLogInUser
const Msg_Report_WillLogOutUser			string = WillLogOutUser
const Msg_Report_TurnOnPC				string = TurnOnPC
const Msg_Report_TurnOffPC				string = TurnOffPC
const Msg_Report_WillTurnOnPC			string = WillTurnOnPC
const Msg_Report_WillTurnOffPC			string = WillTurnOffPC
const Msg_Report_OverCopyToWeDrive		string = "overcopytowedrive"
const Msg_Report_OverCopyToDeptShare	string = "OverCopyToDeptShare"
const Msg_Report_StartBak				string = "startbak"
const Msg_Report_OverBak				string = "overbak"

// msg backup type //////////////////////////////////////////////////////////////

const Msg_Backup_Status_Start			string = "start"
const Msg_Backup_Status_If				string = "if"
const Msg_Backup_Status_Continue		string = "Continue"
const Msg_Backup_Status_Run				string = "run"
const Msg_Backup_Status_Error			string = msgerror

// msg exec type ////////////////////////////////////////////////////////////////

const (
	Msg_Exec_Cmder_ADServer				= iota
	Msg_Exec_Cmder_LocalDaemon
	Msg_Exec_Cmder_LocalUser
)
const Msg_Exec_State_Request			string = "request"
const Msg_Exec_State_Ack				string = "ack"
const Msg_Exec_TurnOffPC				string = TurnOffPC
const Msg_Exec_TurnOffPC_cmd			string = "shutdown -s -t 300"
const Msg_Exec_CancelTurnOffPC			string = "cancel" + TurnOnPC
const Msg_Exec_CancelTurnOffPC_cmd		string = "shutdown -a"
const Msg_Exec_LogOffUser				string = LogOutUser
const Msg_Exec_LogOffUser_cmd			string = "shutdown -l"
const Msg_Exec_UserExec					string = "userexec"
const Msg_Exec_RebootWindows			string = "rebootWindows"
const Msg_Exec_RebootWindows_cmd		string = "shutdown -r -t 15"
const Msg_Exec_InstallSoftware			string = "installsoftware"
const Msg_Exec_CopyWeDrive				string = "copyWeDrive"
const Msg_Exec_CopyDeptShare			string = "copydeptshare"
const Msg_Exec_GUIExec					string = "guiexec"


// msg error type ///////////////////////////////////////////////////////////////

//
const (
	Msg_Reg_Query						= iota
	Msg_Reg_Read
)

//
//
// group Json ////
//

// Basic Json Fromat ///////////////////////////////////////////////////////
type MJbase struct{
	MsgType								string `json:"msgtype"`
	Status								string `json:"status"`
	Explain								string `json:"explain"`
	Username 							string `json:"username"`
	Computername 						string `json:"computername"`
	Dept								string `json:"dept"`
	Timestamp							int64  `json:"timestamp"`
	DataBool							bool   `json:"databool"`
	DataStr								string `json:"datastr"`
	Instruction							string `json:"instruction"`
}
// report Json Format //////////////////////////////////////////////////////
type MJreport struct {
	MJbase
	Version								string `json:"version"`
}
// Exec Json Fromat ///////////////////////////////////////////////////////
type MJexec struct {
	MJbase
	Command								string `json:"command"`
	Cmder								int    `josn:"cmder"`
	SessionID							string `json:"sessionid"`		
	IfDelay								bool   `josn:"ifDelay"`
	Delay								string `json:"delay"`
}
// backup Json Format /////////////////////////////////////////////////////
type MJbackup struct{
	MJbase
	Version								string `json:"version"`
	DiskFree							string `json:"diskfree"`
	//BatchFileExist						bool   `json:"batchfileexist"`
	//BatchFileData						[]byte `json:"batchfiledata"`
	//BatchFileName						string `json:"batchfilename"`
}
type MJreg	struct{
	MJbase
	Action								int    `json:"action"`
	Root								int	   `json:"root"`
	Path								string `json:"path"`
	Key									string `json:"key"`
	DataType							int	   `json:"datatype"`

}
type MJerror struct{
	MJbase
}



//
//
// quickly Get & Set Json 
//


// Report
 
func GJreport(s string) interface{}{
	var rep MJreport
	rep.init(s)
	return rep
}
func (rep * MJreport)Reg_Write_Key_one_AC(key , value string){
	Reg_Write_key_one(
		Reg_Root_ac,
		Reg_Path_home_ac + rep.Computername,
		key,
		value)
}
func (rep * MJreport)init(Report string)  {
	rep.Computername 	= User_computername
	rep.Timestamp		= NowTimestamp()
	rep.MsgType 		= Msg_Report
	rep.Instruction		= Report
	rep.Version			= Version
}



// Exec

func GJexec(s string) MJexec{
	var exec MJexec
	exec.init(s)
	return exec
}
func GJexecAck(s string) interface{}{
	var exec MJexec
	exec.init(s)
	exec.Status			= Msg_Exec_State_Ack
	return exec
}
func GJexecCopyWeDrive(s string) MJexec{
	var exec MJexec
	exec.init(s)
	exec.DataStr		= User_dept
	return exec
}
func GJexecInstallSoftware(b bool,s string) interface{}{
	var exec MJexec
	exec.init(s)
	exec.Status			= Msg_Exec_State_Ack
	exec.DataBool		= b
	exec.Cmder			= Msg_Exec_Cmder_ADServer
	exec.Instruction	= Msg_Exec_InstallSoftware
	exec.Command		= s
	return exec
}
func GJexecUserCmd(s string) interface{}{
	var exec MJexec
	exec.init("")
	exec.Command		= s
	exec.Status			= Msg_Exec_State_Ack
	return exec
}
func GJexecGUI(s string) interface{}{
	var exec MJexec
	exec.init(Msg_Exec_GUIExec)
	exec.Command		= s
	exec.Status			= Msg_Exec_State_Ack
	return exec
}
func (exec * MJexec)init(s string){
	exec.Dept			= User_dept
	exec.Username 		= User_name
	exec.Computername 	= User_computername
	exec.Timestamp		= NowTimestamp()
	exec.MsgType 		= Msg_Exec
	exec.Instruction	= s
	exec.SessionID		= User_sessionID
	exec.Cmder			= Msg_Exec_Cmder_LocalDaemon
	exec.Status			= Msg_Exec_State_Request
	exec.Timestamp		= NowTimestamp()
}


// Backup

func GJbackup(pc string)interface{}{
	var bak MJbackup
	bak.init(pc)
	return bak
}
func (bak * MJbackup)init(pc string)  {
	//bak.Dept			= User_dept
	bak.Timestamp		= NowTimestamp()
	bak.MsgType 		= Msg_Backup
	bak.Version 		= BackupVersion
	bak.Status			= Msg_Backup_Status_Start
	bak.Username 		= GetPrimaryUser(pc)
}


// error

func GJerror(e error)interface{}{
	var err MJerror
	err.init(e)
	return err
}
func (err * MJerror)init (e error){
	err.Username 		= User_name
	err.Dept			= User_dept
	err.Timestamp		= NowTimestamp()
	err.Computername 	= User_computername
	err.MsgType 		= Msg_Error
	err.Instruction		= e.Error()
}
