package com.hzs.common.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 三阶段节点枚举类
 */
@AllArgsConstructor
@Getter
public enum EMemberChildNodeType {


    /**
     * 根节点
     */
    ROOT("0-root", "0", "0-root", null, null),

    /**
     * 第一层：根的子节点
     */
    /**
     * 1-1
     */
    NODE1("1-1", "0-root", "1-1", "point11", "pointMember11"),
    /**
     * 1-2
     */
    NODE2("1-2", "0-root", "1-2", "point12", "pointMember12"),

    /**
     * 第二层
     */
    NODE3("2-1", "1-1", "2-1", "point21", "pointMember21"),
    NODE4("2-2", "1-1", "2-2", "point22", "pointMember22"),
    NODE5("2-3", "1-2", "2-3", "point23", "pointMember23"),
    NODE6("2-4", "1-2", "2-4", "point24", "pointMember24"),

    /**
     * 第三层
     */
    NODE7("3-1", "2-1", "3-1", "point31", "pointMember31"),
    NODE8("3-2", "2-1", "3-2", "point32", "pointMember32"),
    NODE9("3-3", "2-2", "3-3", "point33", "pointMember33"),
    NODE10("3-4", "2-2", "3-4", "point34", "pointMember34"),
    NODE11("3-5", "2-3", "3-5", "point35", "pointMember35"),
    NODE12("3-6", "2-3", "3-6", "point36", "pointMember36"),
    NODE13("3-7", "2-4", "3-7", "point37", "pointMember37"),
    NODE14("3-8", "2-4", "3-8", "point38", "pointMember38");

    /**
     * 点位子会员节点
     */
    private final String id;

    /**
     * 节点
     */
    private final String parentId;

    /**
     * 节点显示名称
     */
    private final String label;

    private final String pointField;

    private final String pointMemberField;

    public Object getFieldValue(Object target, String fieldName) {
        if (target == null || fieldName == null) {
            return null;
        }
        try {
            String methodName = "get" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
            return target.getClass().getMethod(methodName).invoke(target);
        } catch (Exception e) {
            return null;
        }
    }

    public Object getPointValue(Object target) {
        return getFieldValue(target, this.pointField);
    }

    public Object getPointMemberValue(Object target) {
        return getFieldValue(target, this.pointMemberField);
    }
}
