package com.nisemoe.nise

import com.nisemoe.generated.enums.JudgementType
import org.nisemoe.mari.judgements.Judgement
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.util.*


class Format {

    companion object {

        private var targetFormatter: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")

        fun formatLocalDateTime(dateTime: LocalDateTime): String {
            return dateTime
                .plusHours(2)
                .format(targetFormatter)
        }

        fun parseStringToDate(dateTimeStr: String): Date {
            val localDateTime = LocalDateTime.parse(dateTimeStr, targetFormatter)
            return Date.from(localDateTime.atZone(ZoneOffset.UTC).toInstant())
        }

        fun fromJudgementType(circleGuardJudgementType: Judgement.Type): JudgementType {
            return when (circleGuardJudgementType) {
                Judgement.Type.THREE_HUNDRED -> JudgementType.`300`
                Judgement.Type.ONE_HUNDRED -> JudgementType.`100`
                Judgement.Type.FIFTY -> JudgementType.`50`
                Judgement.Type.MISS -> JudgementType.Miss
            }
        }

    }
}