package com.example.demo.controller;


import com.example.demo.domain.Idn;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class IdnController
{
  private final com.example.demo.service.IdnService idnService;

  @GetMapping("/idn/{id}")
  public ResponseEntity<Idn> getIdn(@PathVariable(value = "id") String id)
  {
    return ResponseEntity.ok(idnService.getIdn(Integer.parseInt(id)));
  }

  @GetMapping("/idns")
  public ResponseEntity<Page<Idn>> getPageOfIdns(@RequestParam(value = "page", defaultValue = "0") int page,
                                                 @RequestParam(value = "size", defaultValue = "10") int size)
  {
    return ResponseEntity.ok(idnService.findAll(PageRequest.of(page, size)));
  }

}
