package com.example.demo.service;

import com.example.demo.domain.Idn;
import com.example.demo.repository.IdnRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional(rollbackOn = Exception.class)
@RequiredArgsConstructor
public class IdnService
{
  private final IdnRepository idnRepository;

  public Page<Idn> findAll(Pageable page)
  {
    return idnRepository.findAll(page);
  }

  //casting- ok?
  public ArrayList<Idn> getAll()
  {
    return (ArrayList<Idn>) idnRepository.findAll();
  }

  public Idn getIdn(Integer id)
  {
    return idnRepository.findById(id).orElseThrow(()->new RuntimeException(id+" not found"));
  }

  public ArrayList<Idn> getIdnByType(Integer type)
  {
    return idnRepository.findIdnByType(type);
  }




}
