package com.ffii.fpsms.m18.utils

import com.ffii.fpsms.m18.M18Config
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Lazy
import org.springframework.stereotype.Component
import java.math.BigDecimal
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId

@Component
open class CommonUtils(

) {
    open fun timestampToLocalDateTime(timestamp: Long):LocalDateTime {
        val localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.of("Asia/Hong_Kong"))
        return localDateTime
    }

    @JvmName("listToStringForLongs")
     fun listToString(numbers: List<Long>?, prefix: String, delimiter: String): String {
        if (numbers == null) {
            return ""
        }
        return numbers.joinToString(delimiter) { "$prefix$it" }
    }

    @JvmName("listToStringForStrings")
    fun listToString(strings: List<String>?, prefix: String, delimiter: String): String {
        if (strings == null) {
            return ""
        }
        return strings.joinToString(delimiter) { "$prefix$it" }
    }

    companion object {
        fun getAmt(up: BigDecimal, discount: BigDecimal, qty: BigDecimal): Double {
            return qty.times(BigDecimal(1) - discount).times(up).toDouble()
        }
    }
}