package ru.ulstu.odin.model;

import ru.ulstu.core.error.OdinException;

import java.lang.reflect.Field;
import java.lang.reflect.Type;

public class OdinObjectField extends OdinField {
    private final String path;

    public OdinObjectField(Field field) {
        super(field, OdinFieldType.OBJECT);
        Type fieldElementClass = field.getType();
        try {
            OdinDto someInstance = (OdinDto) ((Class) (fieldElementClass)).newInstance();
            this.path = someInstance.getControllerPath();
        } catch (IllegalAccessException | InstantiationException e) {
            throw new OdinException(String.format("Can't create new instance, check default constructor of %s",
                    fieldElementClass.getTypeName()));
        }
    }

    public String getPath() {
        return path;
    }
}
