package com.eactive.eai.common.sessioninfo.mapper;

import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;

import com.eactive.eai.common.sessioninfo.SessionInfoVO;
import com.eactive.eai.common.sessioninfo.SessionInfoVO.Status;
import com.eactive.eai.data.entity.onl.sessioninfo.SessionInfo;
import com.eactive.eai.data.mapper.GenericMapper;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface SessionInfoMapper extends GenericMapper<SessionInfoVO, SessionInfo> {
	@Mapping(source = "userid", target = "userId")
	@Mapping(source = "brnCd", target = "brnCode")
	@Mapping(source = "brnName", target = "brnName")
	@Mapping(source = "createTime", target = "createTime")
	@Mapping(source = "rofcCd", target = "rofcCode")
	@Mapping(source = "sessionId", target = "sessionId")
	@Mapping(source = "sessionStatus", target = "sessionStatus")
	@Mapping(source = "terminalId", target = "terminalId")
	@Mapping(source = "userName", target = "userName")
	@Mapping(source = "wsocInstance", target = "wsocInstance")
	@Mapping(source = "wsocRemoteAddr", target = "wsocRemoteAddr")
	@Mapping(source = "wsocSessionStatus", target = "wsocSessionStatus")
	@Override
	SessionInfoVO toVo(SessionInfo entity);

	@InheritInverseConfiguration
	@Mapping(source = "sessionStatusInfo", target = "sessionStatus")
	@Mapping(source = "wsocSessionStatusInfo", target = "wsocSessionStatus")
	SessionInfo toEntity(SessionInfoVO vo);

	default Status mapStatus(String status) {
		return Status.inactive.toString().equals(status) ? Status.inactive : Status.active;
	}
	
}
