package com.pictc.datalog;

import java.lang.reflect.Field;

import com.pictc.annotations.datalog.JoinType;
import com.pictc.annotations.datalog.LogJoin;
import com.pictc.utils.DataLogTools;
import com.pictc.utils.SpringAnnotationUtils;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class LogJoinInfo {
	
	private Field field;
	
	private LogJoin join;
	
	public static LogJoinInfo ofAnnotation(Class<?> klazz,Field field) {
		return new LogJoinInfo().setJoin(SpringAnnotationUtils.findAnnotation(field, LogJoin.class)).setField(field);
	}
	
	public LogTableInfo getTableInfo() {
		return DataLogTools.getAnnotation(join.target());
	}

	public boolean isList() {
		return join.type()==JoinType.MANY;
	}
	
	public Class<?> getTargetClass() {
		return join.target();
	}

}
