package io.delphiplatform.api.v3.view;

import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.NativeWebRequest;

import java.util.Optional;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import io.delphiplatform.api.v3.constant.ApplicationConstants;
import io.delphiplatform.api.v3.model.Dsp;
import io.delphiplatform.api.v3.model.Dsps;
import io.delphiplatform.api.v3.view.interceptor.OnlyDeclaredParams;

@Validated
public interface DspsApi {

    default Optional<NativeWebRequest> getRequest() {
        return Optional.empty();
    }

    /**
     * GET /dsps/{dsp_id} : Query for a single DSP Resource route for getting a single &#x60;Dsp&#x60; with filtering
     * based on provided parameters
     *
     * @param dspId (required)
     * @return &#x60;Dsp&#x60; response object (status code 200) or 400 Invalid Input Response (status code 400) or 401
     * Unauthorized (AuthError) Response (status code 401) or 404 Not Found Error Response (status code 404) or 500
     * Internal Error Response (status code 500)
     */
    @RequestMapping(value = "/dsps/{dsp_id}",
        produces = {"application/json"},
        method = RequestMethod.GET)
    default ResponseEntity<Dsp> dspsGet(@PathVariable("dsp_id") String dspId) {
        return findOne(dspId);
    }

    ResponseEntity<Dsp> findOne(String dspId);


    /**
     * GET /dsps : Search for DSPs Resource route for getting a list of &#x60;Dsps&#x60; with filtering based on
     * provided parameters
     *
     * @param limit  The maximum number of &#x60;items&#x60; to return in a single request. (optional)
     * @param offset The number of &#x60;items&#x60; to offset for pagination. (optional)
     * @return &#x60;Dsps&#x60; response object (status code 200) or 400 Invalid Input Response (status code 400) or 401
     * Unauthorized (AuthError) Response (status code 401) or 500 Internal Error Response (status code 500)
     */
    @OnlyDeclaredParams
    @RequestMapping(value = "/dsps",
        produces = {"application/json"},
        method = RequestMethod.GET)
    default ResponseEntity<Dsps> dspsSearch(
        @Min(0) @Max(ApplicationConstants.MAX_PAGE_SIZE)
        @RequestParam(value = "limit", required = false) Integer limit,
        @Min(0)
        @RequestParam(value = "offset", required = false) Integer offset
    ) {
        return getSearchData(limit, offset);
    }

    ResponseEntity<Dsps> getSearchData(Integer limit, Integer offset);

}
