package com.tzld.piaoquan.api.controller.contentplatform;

import com.tzld.piaoquan.api.annotation.RequireSign;
import com.tzld.piaoquan.api.component.VideoVectorProxyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/contentPlatform/videoVector")
@CrossOrigin(origins = "*")
public class ContentPlatformVideoVectorController {

    private static final String MATCH_BY_TEXT_PATH = "recallTest/matchByText";
    private static final String BATCH_BY_TEXT_PATH = "recallTest/batchByText";
    private static final String ALL_CONFIG_CODES_PATH = "videoSearch/getAllConfigCodes";

    @Autowired
    private VideoVectorProxyService proxyService;

    @ApiOperation(value = "转发向量素材单路召回请求")
    @PostMapping(value = "/recallTest/matchByText", produces = MediaType.APPLICATION_JSON_VALUE)
    @RequireSign
    public ResponseEntity<String> matchByText(@RequestBody String requestBody) {
        return jsonResponse(proxyService.post(MATCH_BY_TEXT_PATH, requestBody));
    }

    @ApiOperation(value = "转发向量素材批量召回请求")
    @PostMapping(value = "/recallTest/batchByText", produces = MediaType.APPLICATION_JSON_VALUE)
    @RequireSign
    public ResponseEntity<String> batchByText(@RequestBody String requestBody) {
        return jsonResponse(proxyService.post(BATCH_BY_TEXT_PATH, requestBody));
    }

    @ApiOperation(value = "转发向量配置列表请求")
    @GetMapping(value = "/videoSearch/getAllConfigCodes", produces = MediaType.APPLICATION_JSON_VALUE)
    @RequireSign
    public ResponseEntity<String> getAllConfigCodes() {
        return jsonResponse(proxyService.get(ALL_CONFIG_CODES_PATH));
    }

    private ResponseEntity<String> jsonResponse(String body) {
        return ResponseEntity.ok()
                .contentType(MediaType.APPLICATION_JSON)
                .body(body);
    }
}
