package com.atmob.voiceai.data.api.bean;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;

import com.atmob.common.text.TextUtil;
import com.atmob.voiceai.BR;
import com.atmob.voiceai.sdk.billing.bean.GPProductInfo;
import com.google.gson.annotations.SerializedName;

public class GoodsBean extends BaseObservable implements Comparable<GoodsBean> {
    @SerializedName("id")
    private int id;
    @SerializedName("sort")
    private int sort;
    @SerializedName("name")
    private String name;
    @SerializedName("amount")
    private int amount;
    @SerializedName("originalAmount")
    private int originalAmount;
    @SerializedName("googleProductId")
    private String googleProductId;

    @SerializedName("planId")
    private String planId;

    @SerializedName("lowGoogleProductId")
    private String lowGoogleProductId;

    @SerializedName("days")
    private int days;

    @SerializedName("auth")
    private String auth;
    @SerializedName("content")
    private String content;
    @SerializedName("description")
    private String description;
    @SerializedName("subscriptionMillis")
    private long subscriptionMillis;
    @SerializedName("popular")
    private boolean popular;

    private boolean isSelect;

    private GPProductInfo gpProductInfo;

    public GPProductInfo getGpProductInfo() {
        return gpProductInfo;
    }

    public void setGpProductInfo(GPProductInfo gpProductInfo) {
        this.gpProductInfo = gpProductInfo;
    }

    @Bindable
    public boolean isSelect() {
        return isSelect;
    }

    public void setSelect(boolean select) {
        isSelect = select;
        notifyPropertyChanged(BR.select);
    }

    public String getPlanId() {
        return planId;
    }

    public String getLowGoogleProductId() {
        return lowGoogleProductId;
    }

    public int getDays() {
        return days;
    }

    public int getId() {
        return id;
    }

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

    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAmount() {
        return amount;
    }

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

    public int getOriginalAmount() {
        return originalAmount;
    }

    public void setOriginalAmount(int originalAmount) {
        this.originalAmount = originalAmount;
    }

    public String getGoogleProductId() {
        return googleProductId;
    }

    public void setGoogleProductId(String googleProductId) {
        this.googleProductId = googleProductId;
    }

    public String getAuth() {
        return auth;
    }

    public void setAuth(String auth) {
        this.auth = auth;
    }

    public String getContent() {
        return content;
    }

    public String getPriceContent() {
        if (content == null || content.isEmpty() || gpProductInfo == null) {
            return content;
        }
        float goodsAmount = gpProductInfo.getAmount() / 1000000f;
        String unit = "";
        int unitIndex = gpProductInfo.getFormatPrice().indexOf(String.valueOf(goodsAmount));
        if (unitIndex != -1) {
            unit = gpProductInfo.getFormatPrice().substring(0, unitIndex);
        }
        String unPrice = unit + TextUtil.formatFloatWithout0End(goodsAmount / days, 2);
        return content.replace("%s", unPrice);
    }


    public void setContent(String content) {
        this.content = content;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public long getSubscriptionMillis() {
        return subscriptionMillis;
    }

    public void setSubscriptionMillis(long subscriptionMillis) {
        this.subscriptionMillis = subscriptionMillis;
    }

    public boolean isPopular() {
        return popular;
    }

    public void setPopular(boolean popular) {
        this.popular = popular;
    }


    @Override
    public int compareTo(GoodsBean o) {
        return this.sort - o.sort;
    }
}
