package io.delphiplatform.api.v3.view;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.NativeWebRequest;

import java.util.Optional;

import javax.validation.Valid;

import io.delphiplatform.api.v2.model.AuthTokenRequestBody;
import io.delphiplatform.api.v2.model.AuthTokenResponseBody;

@Validated
public interface OauthApi {

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

    /**
     * POST /oauth/token : get an access token to make authenticated requests
     *
     * @param authTokenRequestBody access token request body (optional)
     * @return Successful Response (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)
     */
    @PostMapping(value = "/oauth/token",
        produces = {MediaType.APPLICATION_JSON_VALUE},
        consumes = {MediaType.APPLICATION_JSON_VALUE})
    ResponseEntity<AuthTokenResponseBody> authPost(@Valid @RequestBody AuthTokenRequestBody authTokenRequestBody);

    @PostMapping(value = "/oauth/token",
        produces = {MediaType.APPLICATION_JSON_VALUE},
        consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
    ResponseEntity<AuthTokenResponseBody> authPost(
        @RequestParam(value = "client_id", required = false) String clientId,
        @RequestParam(value = "client_secret", required = false) String clientSecret,
        @RequestParam(value = "audience", required = false) String audience,
        @RequestParam(value = "grant_type", required = false) String grantType);

}
