package io.delphiplatform.api.v3.view;

import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

import io.delphiplatform.api.v3.model.gras.RepertoireOwner;
import io.delphiplatform.api.v3.model.gras.RepertoireOwners;
import io.delphiplatform.api.v3.rdb.service.RepertoireOwnerService;
import io.delphiplatform.api.v3.view.util.Params;

@Controller
@RequestMapping("${spring.data.rest.base-path:/v3}")
public class RepertoireOwnersApiController implements RepertoireOwnersApi {

    private final RepertoireOwnerService repertoireOwnerService;

    public RepertoireOwnersApiController(
        RepertoireOwnerService repertoireOwnerService) {
        this.repertoireOwnerService = repertoireOwnerService;
    }

    @Override
    public ResponseEntity<RepertoireOwner> findOne(String repOwnerKey) {
        return ResponseEntity.ok(repertoireOwnerService.findOne(repOwnerKey));
    }

    @Override
    public ResponseEntity<RepertoireOwners> getSearchData(Params params) {
        List<RepertoireOwner> items = repertoireOwnerService.find(params);
        return ResponseEntity.ok(new RepertoireOwners().items(items).count(items.size()));
    }
}
