package de.votian.services.repository;

import de.votian.services.entity.ServiceZone;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ServiceZoneRepository extends JpaRepository<ServiceZone, Long> {

    List<ServiceZone> findByHeadquartersIdAndCustomerIdOrderByZoneNo(Long headquartersId, Long customerId);

    @Query("SELECT COALESCE(MAX(sz.zoneNo), -1) FROM ServiceZone sz WHERE sz.headquartersId = :hqId AND sz.customerId = :customerId")
    Integer findMaxZoneNo(@Param("hqId") Long headquartersId, @Param("customerId") Long customerId);
}
