package com.izouma.dingdong.domain.backstage;

import com.izouma.dingdong.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Where(clause = "active = 1")
@ApiModel(value = "商户类别", description = "商户类别")
public class Category extends BaseEntity implements Serializable {
    @Size(max = 30)
    @Column(length = 30)
    @ApiModelProperty(value = "类别名称", name = "name")
    private String name;

    private Long parent;

    private String icon;

    private Boolean active = true;

    @OneToMany
    @JoinColumn(name = "parent", insertable = false, updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    @NotFound(action = NotFoundAction.IGNORE)
    @ApiModelProperty(value = "子分类", name = "children")
    private List<Category> children;
}
