package net.siegeln.cameleer.saas.certificate;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.UUID;

public interface TenantCaCertRepository extends JpaRepository<TenantCaCertEntity, UUID> {

    List<TenantCaCertEntity> findByTenantIdOrderByCreatedAtDesc(UUID tenantId);

    List<TenantCaCertEntity> findByTenantIdAndStatus(UUID tenantId, TenantCaCertEntity.Status status);

    /** All active CAs across all tenants — used to rebuild the aggregated ca.pem. */
    @Query("SELECT c FROM TenantCaCertEntity c WHERE c.status = 'ACTIVE'")
    List<TenantCaCertEntity> findAllActive();
}
