package cd.casic.plugin;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import lombok.*;
import lombok.experimental.Accessors;
import org.pf4j.Plugin;
import org.pf4j.PluginDependency;

import java.util.List;

/**
 * PF4J要用到的DefaultDescriptorStorage里一堆protected方法，所以另外弄了个类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@TableName("sys_plugins")
@Accessors(chain = true)
public class PluginDescriptorStorage {
    @TableId
    private String pluginId;
    private String pluginDescription;
    private String pluginClass = Plugin.class.getName();
    private String version;
    private String requires = "*"; // SemVer format
    private String provider;
    @TableField(typeHandler = JacksonTypeHandler.class)
    private List<PluginDependency> dependencies;
    private String license;
    private String mapperXmlDir;
    private String staticDir;

    private Integer enable;

    private String path;

    @TableField(exist = false)
    private String configFileName;

    @TableField(exist = false)
    private List<String> configFileActive;

    private String pluginDirPath;

    @Getter
    public enum EnableStatus {
        /**
         * 启用
         */
        ENABLE(1, "启用"),
        /**
         * 禁用
         */
        DISABLE(0, "禁用");
        private final Integer code;
        private final String value;

        EnableStatus(Integer code, String value) {
            this.value = value;
            this.code = code;
        }

    }

}

