package com.eactive.eai.rms.onl.dashboard.modern.backup.mapper;

import java.lang.reflect.Field;

public interface BackupMapper<VO, OBJ> {

    VO toVo(OBJ object) throws Exception;

    void setVoValuesToObject(VO vo, OBJ object) throws Exception;

    default <T> T getReflection(Class<?> clazz, String fieldName, Object instance) {
        try {
            Field declaredField = clazz.getDeclaredField(fieldName);
            declaredField.setAccessible(true);
            return (T) declaredField.get(instance);
        } catch (Exception e) {
            throw new RuntimeException("Error occurred during field access", e);
        }
    }

    default void setReflection(Class<?> clazz, String fieldName, Object instance, Object value) {
        try {
            Field declaredField = clazz.getDeclaredField(fieldName);
            declaredField.setAccessible(true);
            declaredField.set(instance, value);
        } catch (Exception e) {
            throw new RuntimeException("Error occurred during field access", e);
        }
    }

}
