package com.zhengmeng.ocrplatform.extract;

import com.zhengmeng.ocrplatform.common.ApiResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/business-profiles")
public class OcrBusinessProfileController {
    private final OcrBusinessProfileService profileService;

    public OcrBusinessProfileController(OcrBusinessProfileService profileService) {
        this.profileService = profileService;
    }

    @GetMapping
    public ApiResponse<List<OcrBusinessProfileService.BusinessProfileItem>> listProfiles() {
        return ApiResponse.ok(profileService.listProfiles());
    }

    @GetMapping("/{profileId}")
    public ApiResponse<OcrBusinessProfileService.BusinessProfileDetail> getProfile(@PathVariable String profileId) {
        return ApiResponse.ok(profileService.getProfile(profileId));
    }

    @PostMapping("/{profileId}/feedback")
    public ApiResponse<OcrBusinessProfileService.BusinessProfileDetail> submitFeedback(
            @PathVariable String profileId,
            @RequestBody OcrBusinessProfileService.ProfileFeedbackRequest request) {
        return ApiResponse.ok(profileService.submitFeedback(profileId, request));
    }

    @PostMapping("/{profileId}/publish")
    public ApiResponse<OcrBusinessProfileService.BusinessProfileDetail> publishProfile(@PathVariable String profileId,
                                                                                       @RequestParam Integer versionNo) {
        return ApiResponse.ok(profileService.publishProfile(profileId, versionNo));
    }
}
