package tech.easyflow.chatlog.support;

import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.ZoneId;
import java.util.Date;

@Component
public class ChatTableRouter {

    public String resolveSessionTable() {
        return ChatConstants.SESSION_TABLE;
    }

    public String resolveLogTable(Date created) {
        LocalDate localDate = created.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
        return resolveLogTable(YearMonth.from(localDate));
    }

    public String resolveLogTable(YearMonth month) {
        return ChatConstants.CHAT_LOG_PREFIX + month.toString().replace("-", "");
    }

    public YearMonth resolveLogMonth(Date created) {
        return YearMonth.from(created.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
    }
}
