package com.izouma.dingdong.domain.merchant;

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.math.BigDecimal;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Where(clause = "enabled = 1")
//@JsonIgnoreProperties(value = { "hibernateLazyInitializer"})
@ApiModel(value = "GoodsSpecification", description = "商品规格")
public class GoodsSpecification extends BaseEntity implements Serializable {

    @ApiModelProperty("商品id")
    private Long goodsId;

    @Size(max = 30)
    @Column(length = 30)
    private String name;

    @ApiModelProperty(value = "价钱", name = "amount")
    private BigDecimal amount;

    private Long parent;

    @ApiModelProperty(value = "可多选", name = "multiple")
    private Boolean multiple;

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

    @Builder.Default
    @Column(nullable = false)
    private Boolean enabled = true;
}
