package com.red.circle.order.infra.database.rds.entity.order;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.red.circle.framework.mybatis.entity.TimestampBaseEntity;
import java.sql.Timestamp;
import java.util.Objects;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * google 购买退款订单.
 * </p>
 *
 * @author pengliang
 * @since 2021-05-24
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("order_google_voided_purchase")
public class OrderGoogleVoidedPurchase extends TimestampBaseEntity {

  private static final long serialVersionUID = 1L;

  /**
   * 主键标识.
   */
  @TableId(value = "id", type = IdType.ASSIGN_ID)
  private Long id;

  /**
   * 来源平台.
   */
  @TableField("sys_origin")
  private String sysOrigin;

  /**
   * 订单用户.
   */
  @TableField("user_id")
  private Long userId;

  /**
   * 订单号.
   */
  @TableField("order_id")
  private String orderId;

  /**
   * 购买时间.
   */
  @TableField("purchase_time_millis")
  private Timestamp purchaseTimeMillis;

  /**
   * 购买token.
   */
  @TableField("purchase_token")
  private String purchaseToken;

  /**
   * 无效购买的发起者，可能的值为：0。用户1.开发者2. Google.
   */
  @TableField("voided_source")
  private Integer voidedSource;

  /**
   * 购买被取消的原因，可能的值为：0。其他1.悔恨2.未收到3.缺陷4.意外购买5.欺诈6.友好欺诈7.拒付.
   */
  @TableField("voided_reason")
  private Integer voidedReason;

  /**
   * 描述.
   */
  @TableField("description")
  private String description;

  public String getVoidedSourceString() {
    if (Objects.equals(voidedReason, 0)) {
      return "用户";
    }
    if (Objects.equals(voidedReason, 1)) {
      return "开发者";
    }
    if (Objects.equals(voidedReason, 2)) {
      return "Google";
    }
    return "未知";
  }

  public boolean voidedSourceIsUser() {
    return Objects.equals(voidedSource, 0);
  }

  public boolean voidedSourceIsGoogle() {
    return Objects.equals(voidedSource, 2);
  }

  public String getVoidedReasonString() {
    if (Objects.equals(voidedReason, 0)) {
      return "其他";
    }
    if (Objects.equals(voidedReason, 1)) {
      return "悔恨";
    }
    if (Objects.equals(voidedReason, 2)) {
      return "未收到";
    }
    if (Objects.equals(voidedReason, 3)) {
      return "缺陷";
    }
    if (Objects.equals(voidedReason, 4)) {
      return "意外购买";
    }
    if (Objects.equals(voidedReason, 5)) {
      return "欺诈";
    }
    if (Objects.equals(voidedReason, 6)) {
      return "友好欺诈";
    }
    if (Objects.equals(voidedReason, 7)) {
      return "拒付";
    }
    return "未知";
  }

}
