package com.ikon.projectmanagement.repository;

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.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.ikon.projectmanagement.entity.WorkingDaysEntity;

@Repository
public interface WorkingDaysRepository extends JpaRepository<WorkingDaysEntity, UUID> {

    @Query("SELECT w FROM WorkingDaysEntity w LEFT JOIN FETCH w.workingDaysDetails WHERE w.workingId = :id")
    Optional<WorkingDaysEntity> findByIdWithDetails(@Param("id") UUID id);

    Optional<WorkingDaysEntity> findByAccountIdentifier(UUID accountIdentifier);

    List<WorkingDaysEntity> findAllByAccountIdentifier(UUID accountIdentifier);

    Optional<WorkingDaysEntity> findByWorkingId(UUID workingId);

    @Query("SELECT w FROM WorkingDaysEntity w JOIN w.workingDaysDetails d WHERE d.year = :year")
    Optional<WorkingDaysEntity> findByYear(@Param("year") String year);
}