package com.nisemoe.nise

import com.nisemoe.generated.enums.JudgementType
import com.nisemoe.nise.integrations.CircleguardService
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: CircleguardService.JudgementType): JudgementType {
            return when (circleGuardJudgementType) {
                CircleguardService.JudgementType.THREE_HUNDRED -> JudgementType.`300`
                CircleguardService.JudgementType.ONE_HUNDRED -> JudgementType.`100`
                CircleguardService.JudgementType.FIFTY -> JudgementType.`50`
                CircleguardService.JudgementType.MISS -> JudgementType.Miss
            }
        }

    }
}