package com.zioinfo.kintex.visitor.membership;

import com.zioinfo.kintex.auth.KintexPrincipal;
import com.zioinfo.kintex.common.ApiResponse;
import com.zioinfo.kintex.visitor.VisitorAuth;
import com.zioinfo.kintex.visitor.membership.MembershipDtos.MembershipDto;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * F-C6 관람객 멤버십 API — 인증(본인만).
 */
@RestController
@RequestMapping("/api/visitor/membership")
public class MembershipController {

    private final MembershipService service;

    public MembershipController(MembershipService service) {
        this.service = service;
    }

    /** GET /api/visitor/membership — 내 등급·혜택. */
    @GetMapping
    public ApiResponse<MembershipDto> me(@AuthenticationPrincipal KintexPrincipal principal) {
        return ApiResponse.ok(service.myMembership(VisitorAuth.requireUserId(principal)));
    }

    /** POST /api/visitor/membership/buyer-verify?verified= — 바이어 인증 토글(데모). */
    @PostMapping("/buyer-verify")
    public ApiResponse<MembershipDto> buyerVerify(@AuthenticationPrincipal KintexPrincipal principal,
                                                  @RequestParam(defaultValue = "true") boolean verified) {
        return ApiResponse.ok(service.setBuyerVerified(VisitorAuth.requireUserId(principal), verified));
    }
}
