package com.sheep.gamegroup.model.entity;

import android.text.Html;

import com.sheep.gamegroup.util.TimeUtil;

import java.util.Locale;

/**
 * Created by realicing on 2018/9/4.
 * realicing@sina.com
 * {
 * "name": "tesat",
 * "icon": "http:\/\/staticcdn.kuaifazs.com\/upload\/static\/201807\/12\/0a\/35\/HOib9G.png",
 * "online_time": 1531382193,
 * "deadline": 1533023768,
 * "gift_ratio": 0,
 * "consume_amount": 0,
 * "game_id": "",
 * "release_id": 734,
 * "Log": {
 * "Id": 173,
 * "UserId": 63096,
 * "GameId": "",
 * "Platform": 1,
 * "Balance": 50,
 * "TotalAssets": 50,
 * "UpdateTime": 1536022825,
 * "CreateTime": 1536022825
 * }
 * }
 */
public class DownloadWelfare {
    private String name;

    private String icon;

    private long online_time;

    private long deadline;

    private int gift_ratio;

    private int consume_amount;
    private String game_id;
    private int release_id;

    private WelfareLog Log;

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

    public String getName() {
        return this.name;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getIcon() {
        return this.icon;
    }

    public void setOnline_time(int online_time) {
        this.online_time = online_time;
    }

    public long getOnline_time() {
        return this.online_time;
    }

    public void setDeadline(int deadline) {
        this.deadline = deadline;
    }

    public long getDeadline() {
        return this.deadline;
    }

    public void setGift_ratio(int gift_ratio) {
        this.gift_ratio = gift_ratio;
    }

    public int getGift_ratio() {
        return this.gift_ratio;
    }

    public void setConsume_amount(int consume_amount) {
        this.consume_amount = consume_amount;
    }

    public int getConsume_amount() {
        return this.consume_amount;
    }

    public void setLog(WelfareLog Log) {
        this.Log = Log;
    }

    public WelfareLog getLog() {
        return this.Log;
    }

    public void setOnline_time(long online_time) {
        this.online_time = online_time;
    }

    public void setDeadline(long deadline) {
        this.deadline = deadline;
    }

    public String getGame_id() {
        return game_id;
    }

    public void setGame_id(String game_id) {
        this.game_id = game_id;
    }

    public int getRelease_id() {
        return release_id;
    }

    public void setRelease_id(int release_id) {
        this.release_id = release_id;
    }


    @Override
    public boolean equals(Object obj) {
        try {
            return obj instanceof DownloadWelfare && ((DownloadWelfare) obj).getLog().getId() == getLog().getId();
        } catch (Exception e) {
            return true;
        }
    }

    /**
     * 福利内容
     *
     * @return
     */
    public String getGiftRatioText() {
        return String.format(Locale.CHINA, "最低充%d，每充%d送%d", consume_amount, consume_amount, gift_ratio * consume_amount / 100);
    }

    /**
     * 剩余金额
     *
     * @return
     */
    public String getBalanceH5() {
        return String.format(Locale.CHINA, "剩余<font color='#7AD5F6'>%d</font>元", this.Log != null ? this.Log.getBalance() : 0);
    }

    public String getDateText() {
        if (deadline < 1000_000) {
            return "永久";
        }
        return String.format(Locale.CHINA, "%s—%s", TimeUtil.TimeStamp2Date(online_time, "yyyy/MM/dd"), TimeUtil.TimeStamp2Date(deadline, "yyyy/MM/dd"));
    }

    /**
     * 已使用金额
     *
     * @return
     */
    public String getUseBalanceText() {
        int use = this.Log != null ? this.Log.getTotalAssets() - this.Log.getBalance() : 0;
        return use == 0 ? "未使用" : String.format(Locale.CHINA, "已使用%d", use);
    }
}
