package io.delphiplatform.api.v3.view;

import org.springframework.beans.factory.annotation.Autowired;
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.util.OffsetBasedPageRequest;
import io.delphiplatform.api.v3.model.Dsp;
import io.delphiplatform.api.v3.model.Dsps;
import io.delphiplatform.api.v3.rdb.service.DspService;

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

    @Autowired
    private DspService dspService;

    @Override
    public ResponseEntity<Dsp> findOne(String dspId) {
        return ResponseEntity.ok(dspService.findOne(dspId));
    }

    @Override
    public ResponseEntity<Dsps> getSearchData(Integer limit, Integer offset) {
        List<Dsp> dsps = dspService.find(OffsetBasedPageRequest.ofParamsToCamelCase(offset, limit, null, null));
        return ResponseEntity.ok(new Dsps().items(dsps).count(dsps.size()));
    }
}
