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.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import io.delphiplatform.api.v3.constant.ApplicationConstants;
import io.delphiplatform.api.v3.model.Region;
import io.delphiplatform.api.v3.model.Regions;
import io.delphiplatform.api.v3.model.SortOrder;
import io.delphiplatform.api.v3.view.interceptor.OnlyDeclaredParams;

@Validated
public interface RegionsApi {

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

    /**
     * GET /regions/{region_id} : Query for a single Region Resource route for getting a single &#x60;Region&#x60; with
     * filtering based on provided parameters
     *
     * @param regionId (required)
     * @return &#x60;Region&#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 = "/regions/{region_id}",
        produces = {"application/json"},
        method = RequestMethod.GET)
    default ResponseEntity<Region> regionsGet(
        @PathVariable("region_id") String regionId
    ) {
        return findOne(regionId);
    }

    ResponseEntity<Region> findOne(String regionId);


    /**
     * GET /regions : Search for Regions Resource route for getting a list of &#x60;Regions&#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)
     * @param sortBy    Field name by which to sort the data. (optional)
     * @param sortOrder Direction to sort the data. Default: &#x60;desc&#x60; if &#x60;sort_by&#x60; provided.
     *                  (optional, default to desc)
     * @return &#x60;Regions&#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 = "/regions",
        produces = {"application/json"},
        method = RequestMethod.GET)
    default ResponseEntity<Regions> regionsSearch(
        @Min(0) @Max(ApplicationConstants.MAX_PAGE_SIZE) @Valid
        @RequestParam(value = "limit", required = false) Integer limit,
        @Min(0) @Valid
        @RequestParam(value = "offset", required = false) Integer offset,
        @Valid
        @RequestParam(value = "sort_by", required = false) String sortBy,
        @Valid
        @RequestParam(value = "sort_order", required = false, defaultValue = "desc") SortOrder sortOrder
    ) {
        return getSearchData(limit, offset, sortBy, sortOrder);
    }

    ResponseEntity<Regions> getSearchData(Integer limit, Integer offset, String sortBy, SortOrder sortOrder);

}
