package com.ikon.projectmanagement.repository;

import com.ikon.projectmanagement.dto.response.StatusWiseProjectResponseData;
import com.ikon.projectmanagement.entity.Project;

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

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

@Repository
public interface ProjectRepository extends JpaRepository<Project, UUID> {

    List<Project> findByAccountId(UUID accountId);

    Optional<Project> getProjectByProjectIdentifier(UUID projectIdentifier);

    boolean existsByProjectIdentifier(UUID projectIdentifier);

    Optional<Project> findByProjectIdentifier(UUID projectIdentifier);

    Optional<Project> findByAccountIdAndProjectIdentifier(UUID accountId, UUID projectIdentifier);

    @Query("""
            SELECT new com.ikon.projectmanagement.dto.response.StatusWiseProjectResponseData (
                        p.projectStatus,
                        COUNT(p)
                    )FROM Project p GROUP BY p.projectStatus
                """)
    List<StatusWiseProjectResponseData> getProjectStatusCounts();

    List<Project> findByProjectStatusIgnoreCase(String projectStatus);
}
