package com.czg.controller.user;

import com.czg.market.dto.MkCarouselDTO;
import com.czg.market.entity.MkCarousel;
import com.czg.market.entity.MkShareBase;
import com.czg.market.service.MkCarouselService;
import com.czg.market.service.MkShareBaseService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 轮播图配置
 *
 * @author ww
 */
@RestController
@RequestMapping("/user")
public class UCarouselController {

    @Resource
    private MkCarouselService mkCarouselService;

    @Resource
    private MkShareBaseService mkShareBaseService;


    /**
     * 轮播图配置
     */
    @GetMapping("/carousel")
    public CzgResult<List<MkCarousel>> getCarousels(MkCarouselDTO carouselDTO) {
        carouselDTO.setShopId(StpKit.USER.getShopId());
        carouselDTO.setIsEnabled(1);
        return CzgResult.success(mkCarouselService.getCarousels(carouselDTO));
    }

    /**
     * 分享 领取触发
     *
     * @param tagType
     * @param shopId
     * @param fromUserId 分享人的shopUserId
     * @param toUserId   被分享人的shopUserId
     */
    public record ShareClaim(String tagType, Long shopId, Long fromUserId, Long toUserId) {
    }

    /**
     * 分享 基础配置
     */
    @GetMapping("/share")
    public CzgResult<MkShareBase> share(@RequestParam Long shopId) {
        return CzgResult.success(mkShareBaseService.getShareBase(shopId));
    }

    /**
     * 分享 领取触发
     * 会绑定上下级关系
     */
    @PostMapping("/shareClaim")
    public CzgResult<Void> shareClaim(@RequestBody ShareClaim shareClaim) {
        mkShareBaseService.shareClaim(shareClaim.tagType, shareClaim.shopId, shareClaim.fromUserId, shareClaim.toUserId);
        return CzgResult.success();
    }
}