package com.mortals.xhx.common.pdu.gen;


import com.mortals.framework.exception.AppException;
import com.mortals.xhx.common.code.ComponentEnum;
import com.mortals.xhx.common.pdu.gen.component.*;

public abstract class Component extends FieldsItem {

    private String type;

    public Component(String type) {
        this.type = type;
    }


    public abstract FieldsItem buildDefaultComponent(ComponentCons cons);


    public static Component createType(String type) {

        if (type.equals(ComponentEnum.INPUT.getValue())) {
            return new InputComponent(type);
        } else if (type.equals(ComponentEnum.TEXTAREA.getValue())) {
            return new TextAreaComponent(type);
        } else if (type.equals(ComponentEnum.SELECT.getValue())) {
            return new SelectComponent(type);
        } else if (type.equals(ComponentEnum.BUTTON.getValue())) {
            return new ButtonComponent(type);
        } else if (type.equals(ComponentEnum.DATE.getValue())) {
            return new DateComponent(type);
        } else if (type.equals(ComponentEnum.CHECKBOX.getValue())) {
            return new CheckboxComponent(type);
        } else if (type.equals(ComponentEnum.IMAGE.getValue())) {
            return new ImageComponent(type);
        } else if (type.equals(ComponentEnum.AREA.getValue())) {
            return new AreaComponent(type);
        } else {
            throw new AppException(String.format("不支持当前组件类型,Type:%s", type));
        }
    }

    
    public abstract String getType();


    public static void main(String[] args) {

    }
}
