/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.nl.system.service.menu.dto;

import lombok.Data;
import org.nl.common.base.BaseDTO;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;

@Data
public class MenuDto extends BaseDTO implements Serializable {

    private String menu_id;

    private List<MenuDto> children;

    private String type;

    private String permission;

    private String title;

    private Integer menu_sort;

    private String path;
    private String name;

    private String component;

    private String pid;

    private Integer sub_count;

    private Boolean iframe;

    private String system_type;

    private Boolean cache;

    private Boolean hidden;

    private String component_name;

    private String icon;

    private boolean has_children;

    private boolean leaf;

    public Boolean getHas_children() {
        return sub_count > 0;
    }

    public Boolean getLeaf() {
        return sub_count <= 0;
    }

    public String getLabel() {
        return title;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        MenuDto menuDto = (MenuDto) o;
        return Objects.equals(menu_id, menuDto.menu_id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(menu_id);
    }
}
