package com.yaoai.api.controller;

import com.yaoai.api.dto.onboarding.TenantOnboardingRequest;
import com.yaoai.api.service.TenantOnboardingService;
import com.yaoai.common.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Tag(name = "企业入驻", description = "企业入驻申请、证照材料提交与审核状态查询")
@Validated
@RestController
@RequestMapping("/tenant-onboarding")
@RequiredArgsConstructor
public class TenantOnboardingController {

    private final TenantOnboardingService tenantOnboardingService;

    @Operation(summary = "提交企业入驻申请")
    @PostMapping(value = "/applications", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ApiResponse<Map<String, Object>> submit(
            @Valid @ModelAttribute TenantOnboardingRequest request,
            @RequestPart(value = "businessLicense", required = false) MultipartFile businessLicense,
            @RequestPart(value = "legalIdentity", required = false) MultipartFile legalIdentity,
            @RequestPart(value = "authorizationLetter", required = false) MultipartFile authorizationLetter) {
        return ApiResponse.success(tenantOnboardingService.submit(request, businessLicense, legalIdentity, authorizationLetter));
    }

    @Operation(summary = "查询入驻审核状态")
    @GetMapping("/applications/{id}")
    public ApiResponse<Map<String, Object>> detail(@PathVariable Long id) {
        return ApiResponse.success(tenantOnboardingService.getApplication(id));
    }
}
