package com.iqser.red.persistence.service.v1.external.api.impl.controller;

import static com.iqser.red.service.persistence.management.v1.processor.roles.ActionRoles.SEARCH;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.iqser.red.service.persistence.management.v1.processor.client.searchservice.SearchClient;
import com.iqser.red.service.persistence.service.v1.api.external.resource.SearchResource;
import com.iqser.red.service.search.v1.model.SearchRequest;
import com.iqser.red.service.search.v1.model.SearchResult;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
public class SearchController implements SearchResource {

    private final SearchClient searchClient;


    @PreAuthorize("hasAuthority('" + SEARCH + "')")
    public SearchResult search(@RequestBody SearchRequest searchRequest) {

        return searchClient.getDossierStatus(searchRequest);
    }


    @Deprecated
    @PreAuthorize("hasAuthority('" + SEARCH + "')")
    public SearchResult searchDeprecated(@RequestBody SearchRequest searchRequest) {

        searchRequest.setPage(searchRequest.getPage() - 1);
        return searchClient.getDossierStatus(searchRequest);
    }

}
