package com.springboot.cloud.sysadmin.organization.entity.vo;

/*
 **********************************************
 *      DATE           PERSON       REASON
 *    2021-01-05          FXY        Created
 **********************************************
 */

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.springboot.cloud.sysadmin.organization.entity.po.application.ApplicationPopedom;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Data
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Menu {

    @JsonIgnore
    private String parentId;

    @JsonIgnore
    private String id;

    private String redirect;
    private String path;
    private String component;
    private List<Menu> children;
    private String name;
    private boolean hidden;
    private boolean alwaysShow;
    private Meta meta;

    public Menu(String path, String redirect, boolean hidden) {
        this.path = path;
        this.redirect = redirect.equals("") ? null : redirect;
        this.hidden = hidden;
    }

    public Menu(ApplicationPopedom applicationPopedom) {
        this.meta = new Meta();
        this.meta.title = applicationPopedom.getTitle();
        this.meta.icon = applicationPopedom.getIcon();
        String s = Optional.ofNullable(applicationPopedom.getRedirect()).orElseGet(String::new);
        this.redirect = s.equals("") ? null : s;
        this.path = applicationPopedom.getPath();
        this.component = applicationPopedom.getComponent();
        this.name = applicationPopedom.getName();
        this.hidden = applicationPopedom.isHidden();
        this.alwaysShow = applicationPopedom.isAlwaysShow();
        this.id = applicationPopedom.getId();
        this.parentId = applicationPopedom.getParentId();
        this.children = new ArrayList<>();
    }

    @Data
    @JsonInclude(value = JsonInclude.Include.NON_NULL)
    class Meta {
        private String icon;
        private String title;
    }
}
