package com.example.demo.repository;

import com.example.demo.model.MembershipLevel;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface MembershipLevelRepository extends JpaRepository<MembershipLevel, Long> {
    Optional<MembershipLevel> findByDisplayName(String displayName);
    Optional<MembershipLevel> findByName(String name);
    
    @Query("SELECT ml.displayName as levelName, COUNT(um) as userCount " +
           "FROM MembershipLevel ml LEFT JOIN UserMembership um ON ml.id = um.membershipLevelId AND um.status = 'ACTIVE' " +
           "GROUP BY ml.id, ml.displayName")
    List<java.util.Map<String, Object>> findMembershipStats();
}
