package com.mytatvarnsdk.utils;

import android.content.Context;
import android.text.TextUtils;

import androidx.annotation.Nullable;

import cgmblelib.database.entity.PocDevice;
import cgmblelib.database.entity.PocGlucose;
import com.mytatvarnsdk.R;

/**
 * Created by minyuchun on 2019/6/14.
 * CGM工具类
 *
 * @author minyuchun
 */
public class CGMTool {
  @Nullable
  public static String getTitleShow(Context context, PocDevice device, PocGlucose glucose) {
    if (device != null && device.isBound()) {
      if (device.isInit()) {
        //设备初始化
        int day = device.getEndCount() / 480;
        return day + " " + context.getResources().getString(R.string.sensor_data_days);
      } else {
        if (glucose != null) {
          String hour = "";
          String minute = "";
          String day = "";
          if (glucose.getCountdownDays() > 0) {
            day = glucose.getCountdownDays() + context.getResources().getString(R.string.sensor_data_days);
          }
          if (glucose.getCountdownHours() > 0) {
            hour = glucose.getCountdownHours() + context.getResources().getString(R.string.sensor_data_hours);
          }
          if (glucose.getCountdownMinutes() > 0) {
            minute = glucose.getCountdownMinutes() + context.getResources().getString(R.string.sensor_data_mins);
          }
          String time = day + hour + minute;
          if (TextUtils.isEmpty(time)) {
            return "0M";
          } else {
            return time;
          }
        } else {
          int day = device.getEndCount() / 480;
          if (device.getEndCount() % 480 > 0) {
            day = day + 1;
          }
          return day + " " + context.getResources().getString(R.string.sensor_data_days);
        }
      }
    }
    return null;
  }


}
