package com.izouma.dingdong.domain.merchant;

import com.izouma.dingdong.annotations.Searchable;
import com.izouma.dingdong.domain.BaseEntity;
import com.izouma.dingdong.enums.ApplyStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalTime;
import java.util.List;

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

    @ApiModelProperty(value = "商户ID", name = "merchantId")
    private Long merchantId;

    @Searchable
    @ApiModelProperty(value = "商品名称", name = "name")
    private String name;

    @ApiModelProperty(value = "简介", name = "introduction")
    private String introduction;

//    @Column(columnDefinition = "text")
//    @Convert(converter = StringArrayConverter.class)
//    @ApiModelProperty(value = "图片", name = "img")
//    private List<String> img;

    @ApiModelProperty(value = "图片", name = "img")
    private String img;

    @ApiModelProperty(value = "库存", name = "inventory")
    private Integer inventory;

    @ApiModelProperty(value = "销量", name = "sales")
    private Integer totalSales;

    @ApiModelProperty(value = "点赞数量", name = "likes")
    private Integer likes;

    @ApiModelProperty(value = "差评数量", name = "bad")
    private Integer bad;

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

    @ApiModelProperty(value = "折扣价格", name = "discountAmount")
    private BigDecimal discountAmount;

    @ApiModelProperty(value = "招牌", name = "signboard")
    private Boolean signboard;

    @ApiModelProperty(value = "下架", name = "takeOff")
    private Boolean takeOff;

    @ApiModelProperty(value = "是否参与满减", name = "isFullReduction")
    private Boolean isFullReduction;

    @ApiModelProperty(value = "周几", name = "week")
    private String week;

    @ApiModelProperty(value = "供应时间", name = "startTime")
    private LocalTime startTime;

    @ApiModelProperty(value = "供应时间", name = "endTime")
    private LocalTime endTime;

    @ApiModelProperty(value = "包装价格", name = "packingPrice")
    private BigDecimal packingPrice;

    @Column(nullable = false)
    private Boolean enabled;

//    @ApiModelProperty(value = "通过", name = "isPass")
//    private Boolean isPass;

    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "状态", name = "status")
    private ApplyStatus status;

    /**
     * 首页推荐
     */
    @ApiModelProperty(value = "推荐", name = "recommend")
    private Boolean recommend;

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "goodsId")
    private List<GoodsSpecification> specifications;

    @ApiModelProperty(value = "优先级", name = "priority")
    private Integer priority;

    @ApiModelProperty(value = "好评")
    private Boolean praise;

    @ApiModelProperty(value = "人气")
    private Boolean popularity;
}
