package com.eactive.eai.rms.onl.audit.adapter.map;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

import com.eactive.eai.data.mapper.BaseMapperConfig;
import com.eactive.eai.rms.data.entity.onl.audit.CustomRevisionEntity;
import com.eactive.eai.rms.onl.audit.adapter.ui.AuditUI;

@Mapper(config = BaseMapperConfig.class, uses = {})
public interface AuditUIMapper {

	@Mapping(target = "revTstmp", source = "revTstmp")
	@Mapping(target = "revNo", source = "rev")
	@Mapping(target = "revUserId", source = "userId")
	void map(CustomRevisionEntity entity, @MappingTarget AuditUI auditUI);

	default LocalDateTime mapLongToLocalDateTime(long epochTime) {
		Instant instant = Instant.ofEpochMilli(epochTime);
		return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
	}

	default String mapLongToString(long epochTime) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		return LocalDateTime.ofInstant(Instant.ofEpochMilli(epochTime), ZoneId.systemDefault()).format(formatter);
	}
}
