package com.magistr.app.service;

import org.junit.jupiter.api.Test;

import java.time.Clock;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;

import static org.assertj.core.api.Assertions.assertThat;

class BusinessTimeServiceTest {

    private static final ZoneId MOSCOW = ZoneId.of("Europe/Moscow");

    @Test
    void keepsBusinessDateBeforeMoscowMidnight() {
        BusinessTimeService service = new BusinessTimeService(
                Clock.fixed(Instant.parse("2026-01-01T20:59:59Z"), ZoneId.of("UTC")),
                MOSCOW
        );

        assertThat(service.today()).isEqualTo(LocalDate.of(2026, 1, 1));
        assertThat(service.now()).isEqualTo(Instant.parse("2026-01-01T20:59:59Z"));
    }

    @Test
    void changesBusinessDateExactlyAtMoscowMidnight() {
        BusinessTimeService service = new BusinessTimeService(
                Clock.fixed(Instant.parse("2026-01-01T21:00:00Z"), ZoneId.of("UTC")),
                MOSCOW
        );

        assertThat(service.today()).isEqualTo(LocalDate.of(2026, 1, 2));
    }
}
