package cc.winboll.studio.timestamp.utils;

/**
 * @Author ZhanGSKen
 * @Date 2025/05/07 11:03
 * @Describe TimeStampUtil
 */
import android.content.Context;
import android.net.Uri;
import cc.winboll.studio.timestamp.R;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class TimeStampUtil {

    public static final String TAG = "TimeStampUtil";

    volatile static TimeStampUtil _TimeStampUtil;

    Context mContext;
    long mTimeStamp;

    TimeStampUtil(Context context) {
        mContext = context;
        mTimeStamp = System.currentTimeMillis();
    }

    public synchronized static TimeStampUtil getInstance(Context context) {
        if (_TimeStampUtil == null) {
            _TimeStampUtil = new TimeStampUtil(context);
        }
        return _TimeStampUtil;
    }

    public void genTimeStamp() {
        mTimeStamp = System.currentTimeMillis();
    }

    public String getTimeStampShowString() {
        long currentMillis = mTimeStamp;
        Instant instant = Instant.ofEpochMilli(currentMillis);
        LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
        String szTimeStampFormatString = AppConfigsUtil.getInstance(mContext).getAppConfigsModel().getTimeStampFormatString();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(szTimeStampFormatString);
        String formattedDateTime = ldt.format(formatter);
        return formattedDateTime;
    }

    public String getTimeStampCopyString() {
        long currentMillis = mTimeStamp;
        Instant instant = Instant.ofEpochMilli(currentMillis);
        LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
        String szTimeStampFormatString = AppConfigsUtil.getInstance(mContext).getAppConfigsModel().getTimeStampCopyFormatString();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(szTimeStampFormatString);
        String formattedDateTime = ldt.format(formatter);
        return formattedDateTime;
    }
	

	//
	// 播放时间戳确定时的提示音乐
	//
	public static void playNotifyMusic(Context context) {
        // 播放默认短信铃声
        //Uri defaultSmsRingtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        //AudioPlayerUriUtil.playAudio(context, defaultSmsRingtoneUri);

        // 播放应用铃声
        // 获取MP3文件的Uri
        Uri soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.diweiyi);
        AudioPlayerUriUtil.playAudio(context, soundUri);
	}
}
