GuildMemberData = class("GuildMemberData")

GuildMemberDataType = {}

local function mapGuildEnumProp(enum,propName)
	if(enum) then
		GuildMemberDataType[enum] = propName
	else
		redlog(string.format("GuildCmd_pb enum is nil! propName is %s",propName))
	end
end

mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_NAME,"name")
-- 基礎等級
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_BASELEVEL,"baselevel")
-- 頭像
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_PORTRAIT,"portrait")
-- 相框
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_FRAME,"frame")
-- 職業
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_PROFESSION,"profession")
-- 目前貢獻度（會有消耗）
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_CONTRIBUTION,"contribution")
-- 總貢獻度（在這個公會的總貢獻度）
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_TOTALCONTRIBUTION,"totalcontribution")
-- 每週貢獻度
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_WEEKCONTRIBUTION,"weekcontribution")
-- 每週貢獻的公會資金 跟貢獻度不一樣
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_WEEKASSET,"weekasset")
-- 進入公會時間
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_ENTERTIME,"entertime")
-- 離線時間
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_OFFLINETIME,"offlinetime")
-- 幫會職位
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_JOB,"job")
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_HAIR,"hair")
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_EYE,"eye")
-- 頭髮顏色
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_HAIRCOLOR,"haircolor")
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_BODY,"body")
-- 頭飾
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_HEAD,"head")
-- 臉部
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_FACE,"face")
-- 嘴部
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_MOUTH,"mouth")
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_LEVELUPEFFECT,"levelupeffect")
-- 公會成員切線
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_ZONEID,"zoneid")
-- 初始化賦值 不會更新到的屬性
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_GENDER,"gender")

mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_WEEKBCOIN,"weekbcoin")
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_TOTALBCOIN,"totalcoin")
--語音
mapGuildEnumProp(GuildCmd_pb.EGUILDMEMBERDATA_REALTIMEVOICE,"realtimevoice")

GuildSummaryStringType = {
	["name"] = 1,
}

function GuildMemberData:ctor(guildMemberData, guildData)
	self.guildData = guildData;
	self:SetData(guildMemberData);
end

function GuildMemberData:SetData(gmdata)
	if(gmdata)then
		self.id = gmdata.charid;
		self.name = gmdata.name;
		if(gmdata and gmdata.building)then
			self.buildingLevelUp = gmdata.building.buildings
		end

		local updateStr = "GuildMemberData(Init): ";
		updateStr = updateStr..string.format("| %s:%s", "name", tostring(self.name));

		for _,key in pairs(GuildMemberDataType) do
			if(gmdata[key])then
				self[key] = gmdata[key];
				updateStr = updateStr..string.format("| %s:%s", key, gmdata[key]);
			end
		end

		if self.realtimevoice == nil then
			--這裡假如沒有授權伺服器發過來的就是nil
			self.realtimevoice = false
		end	

		--helplog(updateStr);
	end
end

function GuildMemberData:UpdateData(updateDatas)
	local updateStr = "GuildMemberData(Update): ";
	updateStr = updateStr..string.format("| %s:%s", "name", self.name);
	local oldJob = member.job;

	for i=1,#updateDatas do
		local data = updateDatas[i];
		local key = GuildMemberDataType[data.type];
		if(key)then
			if(GuildSummaryStringType[key])then
				self[key] = data.data;
			else
				self[key] = data.value;
			end
			updateStr = updateStr..string.format("| %s:%s",key,tostring(data.value));
		end
	end

	--helplog(updateStr);
	if(self.id == Game.Myself.data.id and oldJob ~= self.job)then
		FunctionGuild.Me():MyGuildJobChange(oldJob, self.job);
	end
end

function GuildMemberData:GetJobName()
	if(self.guildData and self.job)then
		return self.guildData:GetJobName(self.job);
	end
end

function GuildMemberData:IsOffline()
	if(self.offlinetime)then
		return self.offlinetime ~= 0;
	end
	return false;
end

function GuildMemberData:IsBoy()
	return self.gender == ProtoCommon_pb.EGENDER_MALE;
end

function GuildMemberData:NeedPlayLevelUpEffect()
	return self.levelupeffect == true or self.levelupeffect == 1;
end

function GuildMemberData:GetBuildingLevelup()
	return self.buildingLevelUp
end
--語音是否禁言
function GuildMemberData:IsRealtimevoice()
	return self.realtimevoice == true or  self.realtimevoice == 1
end
--服務端說前端自己儲存這個值
function GuildMemberData:SetRealtimevoiceValue(value)
	self.realtimevoice = value
end

function GuildMemberData:GetCharId()
	return self.id
end



