package com.cameleer.server.app.storage;

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

import static org.junit.jupiter.api.Assertions.*;

class FlywayMigrationIT extends AbstractPostgresIT {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Test
    void allMigrationsApplySuccessfully() {
        // Verify RBAC tables exist
        Integer userCount = jdbcTemplate.queryForObject(
                "SELECT COUNT(*) FROM users", Integer.class);
        assertEquals(0, userCount);

        Integer roleCount = jdbcTemplate.queryForObject(
                "SELECT COUNT(*) FROM roles", Integer.class);
        assertEquals(4, roleCount); // AGENT, VIEWER, OPERATOR, ADMIN

        Integer groupCount = jdbcTemplate.queryForObject(
                "SELECT COUNT(*) FROM groups", Integer.class);
        assertEquals(1, groupCount); // Admins

        // Verify config/audit tables exist
        Integer configCount = jdbcTemplate.queryForObject(
                "SELECT COUNT(*) FROM server_config", Integer.class);
        assertEquals(0, configCount);

        Integer auditCount = jdbcTemplate.queryForObject(
                "SELECT COUNT(*) FROM audit_log", Integer.class);
        assertEquals(0, auditCount);

        Integer appConfigCount = jdbcTemplate.queryForObject(
                "SELECT COUNT(*) FROM application_config", Integer.class);
        assertEquals(0, appConfigCount);

        Integer appSettingsCount = jdbcTemplate.queryForObject(
                "SELECT COUNT(*) FROM app_settings", Integer.class);
        assertEquals(0, appSettingsCount);
    }
}
