package com.izouma.nineth.domain;

import com.izouma.nineth.annotations.Searchable;
import com.izouma.nineth.converter.FileObjectListConverter;
import com.izouma.nineth.converter.PropertyListConverter;
import com.izouma.nineth.enums.CollectionType;
import com.izouma.nineth.enums.OrderStatus;
import com.izouma.nineth.enums.PayMethod;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.List;

@Data
@Entity
@Table(name = "order_info")
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel("订单")
public class Order extends BaseEntity {

    @ApiModelProperty("用户ID")
    @Searchable
    private Long userId;

    @ApiModelProperty("藏品ID")
    @Searchable
    private Long collectionId;

    @ApiModelProperty("数量")
    private int qty;

    @ApiModelProperty("名称")
    @Searchable
    private String name;

    @ApiModelProperty("图片")
    @Convert(converter = FileObjectListConverter.class)
    @Column(columnDefinition = "TEXT")
    private List<FileObject> pic;

    @ApiModelProperty("详情")
    @Column(columnDefinition = "TEXT")
    private String detail;

    @Column(columnDefinition = "TEXT")
    @Convert(converter = PropertyListConverter.class)
    @ApiModelProperty("特性")
    private List<CollectionProperty> properties;

    @ApiModelProperty("分类")
    private String category;

    @ApiModelProperty("是否可转售")
    private boolean canResale;

    @ApiModelProperty("版税比例")
    private int royalties;

    @ApiModelProperty("手续费比例")
    private int serviceCharge;

    @ApiModelProperty("类型")
    @Enumerated(EnumType.STRING)
    private CollectionType type;

    @ApiModelProperty("铸造者")
    @Searchable
    private String minter;

    @ApiModelProperty("铸造者ID")
    @Searchable
    private Long minterId;

    @ApiModelProperty("铸造者头像")
    private String minterAvatar;

    @ApiModelProperty("价格")
    @Column(precision = 10, scale = 2)
    private BigDecimal price;

    @ApiModelProperty("gas费")
    @Column(precision = 10, scale = 2)
    private BigDecimal gasPrice;

    @ApiModelProperty("总价")
    @Column(precision = 10, scale = 2)
    private BigDecimal totalPrice;

    @ApiModelProperty("状态")
    @Enumerated(EnumType.STRING)
    private OrderStatus status;

    @ApiModelProperty("支付方式")
    @Enumerated(EnumType.STRING)
    private PayMethod payMethod;

    @ApiModelProperty("交易ID")
    @Searchable
    private String transactionId;

    @ApiModelProperty("支付时间")
    private LocalDateTime payTime;

    @ApiModelProperty("取消时间")
    private LocalDateTime cancelTime;

    @ApiModelProperty("交易hash")
    private String txHash;

    @ApiModelProperty("消耗gas")
    private BigInteger gasUsed;

    @ApiModelProperty("区块高度")
    private BigInteger blockNumber;

    @ApiModelProperty("收货人")
    private String contactName;

    @ApiModelProperty("收货电话")
    private String contactPhone;

    @ApiModelProperty("收货地址")
    private String address;
}
