package com.cameleer.server.app.license;

import com.cameleer.server.app.AbstractPostgresIT;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

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

class LicenseUsageReaderIT extends AbstractPostgresIT {

    @Autowired LicenseUsageReader reader;

    @BeforeEach
    void cleanDb() {
        // Defensive cleanup so the test is order-independent under Testcontainer reuse — sibling
        // ITs may have left envs/apps that would otherwise inflate the snapshot counts.
        jdbcTemplate.update("DELETE FROM deployments");
        jdbcTemplate.update("DELETE FROM app_versions");
        jdbcTemplate.update("DELETE FROM apps");
        jdbcTemplate.update("DELETE FROM environments WHERE slug != 'default'");
    }

    @Test
    void emptyDb_returnsZeros() {
        var snap = reader.snapshot();
        assertThat(snap.get("max_apps")).isEqualTo(0L);
        assertThat(snap.get("max_environments")).isLessThanOrEqualTo(1L); // V1 seeds default env
        assertThat(snap.get("max_total_cpu_millis")).isEqualTo(0L);
    }
}
