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

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

import com.eactive.eai.common.pushinfo.PushInfoDetailVO;
import com.eactive.eai.common.pushinfo.PushInfoDetailVO.Result;
import com.eactive.eai.data.entity.onl.pushinfo.PushInfoDetail;
import com.eactive.eai.data.mapper.BaseMapperConfig;
import com.eactive.eai.data.mapper.GenericMapper;

@Mapper(config = BaseMapperConfig.class, unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface PushInfoDetailMapper extends GenericMapper<PushInfoDetailVO, PushInfoDetail> {

	@Mapping(source = "guid", target = "guid")
	@Mapping(source = "userid", target = "userId")
	@Mapping(source = "sessionId", target = "sessionId")
	@Mapping(source = "instanceId", target = "instanceId")
	@Mapping(source = "wsocRemoteAddr", target = "wsocRemoteAddr")
	@Mapping(source = "pushResult", target = "pushResult")
	@Mapping(source = "errorContent", target = "errorContent")
	@Mapping(source = "pushDatetime", target = "pushDatetime")
	@Override
	PushInfoDetailVO toVo(PushInfoDetail entity);

	@Mapping(source = "pushResult", target = "pushResult")
	@InheritInverseConfiguration
	PushInfoDetail toEntity(PushInfoDetailVO vo);

	default Result mapStringToResult(String pushResult) {
		return Result.valueOf(pushResult);
	}

	default String mapResultToString(Result result) {
		return result.name();
	}
}
