package com.sysu.admin.support.system.menu;

import com.sysu.admin.utils.i18n.MessageUtils;
import com.xiesx.fastboot.core.jpa.entity.JpaPlusEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

/**
 * @title Menu
 * @description
 * @author XIE
 * @date 2020年4月24日下午10:03:32
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@FieldNameConstants(innerTypeName = "FIELDS")
@Table(name = "sys_menu")
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicInsert
@DynamicUpdate
public class SMenu extends JpaPlusEntity<SMenu> {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @CreatedDate
    @Column(updatable = false, nullable = false)
    private Date createDate;

    @LastModifiedDate
    @Column(nullable = false)
    private Date updateDate;

    @Column
    private Long parent;

    @Column
    private String name;

    public String getName(){
        int index = name.indexOf("menu.");
        if(index > -1){
            return MessageUtils.get(name);
        }
        return name;
    }

    @Column
    private String href;

    @Column
    private String icon;

    @Column
    private Integer sort;

    @Column
    private String permission;

    @Column
    private Integer isMenu;

    @Column
    private Integer isOpen;

    @Column
    private Integer isEnable;

}
