package com.huimv.employment.controller.publicapi;

import com.huimv.employment.common.web.R;
import com.huimv.employment.service.draft.DraftService;
import com.huimv.employment.service.draft.dto.DraftDetailResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用工草稿公开查询（无需 JWT）。
 * <p>路径不在 {@code /api/v1/mp/**} 下，JwtAuthFilter 不会拦截。</p>
 */
@RestController
@RequestMapping("/api/v1/public/drafts")
@Tag(name = "用工草稿（公开）", description = "无需登录，按小程序码 scene 查询草稿详情")
public class PublicDraftController {

    private final DraftService draftService;

    public PublicDraftController(DraftService draftService) {
        this.draftService = draftService;
    }

    @GetMapping
    @Operation(summary = "公开查询用工草稿详情",
            description = "无需 Authorization。scene 为小程序码参数（订单编号，与 fe_registration_batch.qr_token 一致）。"
                    + "返回字段与登录态详情一致（含 fields、qr_code_url）。")
    public R<DraftDetailResponse> getDetail(
            @Parameter(description = "小程序码 scene / 订单编号", required = true, example = "ord_123")
            @RequestParam("scene") String scene) {
        return R.ok(draftService.getPublicDetailByScene(scene));
    }
}
