package com.izouma.dingdong.domain;


import com.izouma.dingdong.converter.LongArrayConverter;
import com.izouma.dingdong.domain.merchant.Goods;
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 java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Where(clause = "enabled = 1")
@ApiModel(value = "订单商品及规格", description = "订单商品及规格")
public class OrderGoodsSpec extends BaseEntity implements Serializable {
//    private Long userId;

    @ApiModelProperty(value = "订单ID", name = "orderId")
    private Long orderInfoId;

    @ApiModelProperty(value = "购物车ID", name = "cartId")
    private Long shoppingCartId;

    @ApiModelProperty(value = "商品ID", name = "goodsId")
    private Long goodsId;

//    private String goodsName;

    // private String specificationId;

    @Convert(converter = LongArrayConverter.class)
    private List<Long> specificationId;

    @ApiModelProperty(value = "规格", name = "specification")
    private String specification;

    @ApiModelProperty(value = "数量", name = "num")
    private Integer num;

    @ApiModelProperty(value = "商品价格", name = "goodsPrice")
    private BigDecimal goodsPrice;

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

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "goodsId", insertable = false, updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    @NotFound(action = NotFoundAction.IGNORE)
    private Goods goods;

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

}
