package com.datarecovery.master.data.api.bean;

import androidx.annotation.IntDef;

import com.atmob.common.runtime.ContextUtil;
import com.datarecovery.master.R;
import com.datarecovery.master.module.member.MemberType;
import com.datarecovery.master.utils.DateUtil;
import com.google.gson.annotations.SerializedName;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Objects;

public class OrderBean {
    @SerializedName("itemName")
    private String itemName;
    @SerializedName("amount")
    private int amount;
    @SerializedName("outTradeNo")
    private String outTradeNo;
    @SerializedName("id")
    private int id;

    @SerializedName("itemId")
    private int itemId;
    @SerializedName("authCode")
    private String authCode;

    @SerializedName("auths")
    private String auths;
    @SerializedName("startTimestamp")
    private long startTimestamp;
    @SerializedName("endTimestamp")
    private long endTimestamp;
    @SerializedName("permanent")
    private boolean permanent;

    @SerializedName("tutorialUrl")
    private String tutorialLink;

    @SerializedName("createTime")
    private String createTime;

    @SerializedName("payMethod")
    private int payMethod;

    @SerializedName("payPlatform")
    private int payPlatform;

    @OrderStatus
    @SerializedName("status")
    private int status;

    @SerializedName("expirationDesc")
    private String expirationDesc;


    @IntDef({OrderStatus.SUCCESS, OrderStatus.TODO})
    @Retention(RetentionPolicy.SOURCE)
    public @interface OrderStatus {
        int SUCCESS = 0;
        int TODO = 2;
    }

    public String getCreateTime() {
        if ("null".equals(createTime)) {
            return "";
        }
        return createTime;
    }

    public String getExpirationDesc() {
        return expirationDesc;
    }

    public int getItemId() {
        return itemId;
    }

    public int getPayMethod() {
        return payMethod;
    }

    public int getPayPlatform() {
        return payPlatform;
    }

    public int getStatus() {
        return status;
    }

    public String getTutorialLink() {
        return tutorialLink;
    }

    public String getAuths() {
        return auths;
    }

    public String getExpireDate() {
        if (permanent) {
            return "永久有效";
        } else {
            return DateUtil.formatNormalDate(DateUtil.YYYY_MM_DD_HH_MM_SS, endTimestamp);
        }
    }


    public String getItemName() {
        return itemName;
    }

    public void setItemName(String itemName) {
        this.itemName = itemName;
    }

    public String getAmount() {
        return String.valueOf(amount / 100.0);
    }

    public int getFenAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public String getOutTradeNo() {
        return outTradeNo;
    }

    public void setOutTradeNo(String outTradeNo) {
        this.outTradeNo = outTradeNo;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getAuthCode() {
        return authCode;
    }

    public void setAuthCode(String authCode) {
        this.authCode = authCode;
    }

    public long getStartTimestamp() {
        return startTimestamp;
    }

    public void setStartTimestamp(long startTimestamp) {
        this.startTimestamp = startTimestamp;
    }

    public long getEndTimestamp() {
        return endTimestamp;
    }

    public void setEndTimestamp(long endTimestamp) {
        this.endTimestamp = endTimestamp;
    }

    public boolean isPermanent() {
        return permanent;
    }

    public void setPermanent(boolean permanent) {
        this.permanent = permanent;
    }

    public boolean isShowLink() {
        return (Objects.equals(auths, MemberType.APP_WX_FRIEND_RECOVER) || Objects.equals(auths, MemberType.APP_WX_MESSAGE_RECOVER) || Objects.equals(auths, MemberType.APP_SUPER_RECOVER)) && status == OrderStatus.SUCCESS;
    }

    public String getOrderStatusDesc() {
        switch (status) {
            case OrderStatus.SUCCESS:
                return ContextUtil.getContext().getString(R.string.order_success);
            case OrderStatus.TODO:
                return ContextUtil.getContext().getString(R.string.order_todo_pay);
            default:
                return "";
        }
    }
}
