package com.magistr.app.model;

import org.junit.jupiter.api.Test;

import java.time.LocalDate;

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

class ScheduleRuleTest {

    @Test
    void activeOnUsesStatusAndValidityRange() {
        ScheduleRule rule = new ScheduleRule();
        rule.setValidFrom(LocalDate.of(2026, 2, 1));
        rule.setValidTo(LocalDate.of(2026, 2, 10));

        assertThat(rule.isActiveOn(LocalDate.of(2026, 1, 31))).isFalse();
        assertThat(rule.isActiveOn(LocalDate.of(2026, 2, 1))).isTrue();
        assertThat(rule.isActiveOn(LocalDate.of(2026, 2, 10))).isTrue();
        assertThat(rule.isActiveOn(LocalDate.of(2026, 2, 11))).isFalse();

        rule.setStatus(LifecycleEntity.STATUS_ARCHIVED);

        assertThat(rule.isActiveOn(LocalDate.of(2026, 2, 5))).isFalse();
    }

    @Test
    void archiveAndRestoreToggleStatus() {
        ScheduleRule rule = new ScheduleRule();

        rule.archive();

        assertThat(rule.isArchivedRecord()).isTrue();
        assertThat(rule.isActiveOn(LocalDate.now())).isFalse();

        rule.restore();

        assertThat(rule.isActiveRecord()).isTrue();
        assertThat(rule.getValidTo()).isNull();
    }
}
