package com.jeesharp.business.marketing.memberTenant.controller;

import com.jeesharp.business.modules.marketing.api.MarketingMobileApi;
import com.jeesharp.business.modules.marketing.memberTenant.dto.MemberTenantJoinDTO;
import com.jeesharp.business.modules.marketing.memberTenant.enums.MemberTenantJoinSourceEnum;
import com.jeesharp.business.modules.marketing.memberTenant.vo.MemberTenantMobileVO;
import com.jeesharp.framework.memberauth.utils.MemberAuthUtils;
import com.jeesharp.framework.memberauth.web.BaseMobileController;
import com.jeesharp.framework.pojo.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 移动端店铺会员接口：扫码入会、我的店铺列表。
 *
 * @author jeesharp
 * @since 2026-06-25
 */
@Slf4j
@RestController
@RequestMapping("${jeesharp.web.mobilePath}/marketing/memberTenant")
@Tag(name = "移动端-店铺会员", description = "扫码入会、我的店铺")
@AllArgsConstructor
public class MemberTenantMobileController extends BaseMobileController {

    private final MarketingMobileApi marketingMobileApi;

    @Operation(summary = "扫码入会 / 绑定店铺")
    @PostMapping("/join")
    public AjaxResult<MemberTenantMobileVO> join(@RequestBody @Valid MemberTenantJoinDTO dto) {
        String memberId = MemberAuthUtils.getLoginUserId();
        dto.setJoinSource(MemberTenantJoinSourceEnum.QR_SCAN.getValue());
        return AjaxResult.okData(marketingMobileApi.joinMemberTenant(memberId, dto));
    }

    @Operation(summary = "我的店铺列表")
    @GetMapping("/myTenants")
    public AjaxResult<List<MemberTenantMobileVO>> myTenants() {
        String memberId = MemberAuthUtils.getLoginUserId();
        return AjaxResult.okData(marketingMobileApi.listMyTenants(memberId));
    }

    @Operation(summary = "我可核销的店铺列表")
    @GetMapping("/myClerkTenants")
    public AjaxResult<List<MemberTenantMobileVO>> myClerkTenants() {
        String memberId = MemberAuthUtils.getLoginUserId();
        return AjaxResult.okData(marketingMobileApi.listMyClerkTenants(memberId));
    }
}
