package com.izouma.jiashanxia.domain;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.izouma.jiashanxia.annotations.Searchable;
import com.izouma.jiashanxia.enums.PayMethod;
import com.izouma.jiashanxia.enums.TransactionType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;

@AllArgsConstructor
@NoArgsConstructor
@Entity
@Builder
@Data
@ApiModel(value = "佣金记录", description = "CommissionRecord")
public class CommissionRecord extends BaseEntity implements Serializable {
    @ApiModelProperty(value = "用户ID", name = "userId")
    private Long userId;

    @Enumerated(EnumType.STRING)
    @ApiModelProperty(value = "交易类型", name = "transactionType")
    private TransactionType transactionType;

    @Column(nullable = false)
    @ApiModelProperty(value = "交易金额", name = "money")
    private BigDecimal amount;

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

    @Searchable
    @ApiModelProperty(value = "交易单号", name = "transactionId")
    private String transactionId;

    @ApiModelProperty(value = "备注", name = "remark")
    private String remark;

    @ExcelIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "userId", insertable = false, updatable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
    @NotFound(action = NotFoundAction.IGNORE)
    private User user;

    private Long fromUserId;
}
