package co.yixiang.yshop.module.member.controller.app.burypoint;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.util.servlet.ServletUtils;
import co.yixiang.yshop.framework.operatelog.core.annotations.OperateLog;
import co.yixiang.yshop.module.member.controller.admin.burypoint.vo.BuryPointCreateReqVO;
import co.yixiang.yshop.module.member.service.burypoint.BuryPointService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
import static co.yixiang.yshop.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Tag(name = "APP - 埋点")
@RequestMapping("/bury-point")
public class AppBuryPointController {

    @Resource
    private BuryPointService buryPointService;

    @PostMapping("/create")
    @Operation(summary = "创建埋点")
    @OperateLog(enable = false)
    public CommonResult<Long> createBuryPoint(@RequestBody BuryPointCreateReqVO createReqVO) {
        Long uid = getLoginUserId();
        createReqVO.setUserId(uid);
        createReqVO.setIp(ServletUtils.getClientIP());
        return success(buryPointService.createBuryPoint(createReqVO));
    }
}
