package com.ruoyi.cai.controller.app;


import com.ruoyi.cai.dto.app.query.AnchorUpdateReq;
import com.ruoyi.cai.dto.app.vo.AnchorJoinHomeVo;
import com.ruoyi.cai.dto.app.vo.AnchorVo;
import com.ruoyi.cai.dto.app.vo.CameraAuditVo;
import com.ruoyi.cai.manager.CurrentUserManager;
import com.ruoyi.cai.service.AnchorApplyService;
import com.ruoyi.cai.service.AnchorService;
import com.ruoyi.cai.service.UserCameraAuditService;
import com.ruoyi.cai.service.UserService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.helper.LoginHelper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/anchor")
@Tag(name = "主播相关接口")
public class AnchorAppController {

    @Autowired
    private CurrentUserManager currentUserManager;
    @Autowired
    private UserCameraAuditService userCameraAuditService;
    @Autowired
    private AnchorService anchorService;
    @Autowired
    private UserService userService;
    @Autowired
    private AnchorApplyService anchorApplyService;

    @GetMapping("/info")
    @Operation(summary = "当前用户的主播信息")
    public R<AnchorVo> anchorInfo(){
        return R.ok(currentUserManager.anchorInfo());
    }


    @PostMapping("/update")
    @Operation(summary = "修改当前用户的主播信息")
    public R<Boolean> anchorUpdate(@RequestBody AnchorUpdateReq anchorUpdate){
        return R.ok(currentUserManager.anchorUpdate(anchorUpdate));
    }

    @GetMapping("/cameraAudit")
    @Operation(summary = "主播自拍认证")
    public R<CameraAuditVo> cameraAudit(){
        Long userId = LoginHelper.getUserId();
        return R.ok(userCameraAuditService.cameraAudit(userId));
    }

    @PostMapping("/uploadCameraAudit")
    @Operation(summary = "上传自拍认证")
    public R<Boolean> uploadCameraAudit(@RequestBody CameraAuditVo vo){
        Long userId = LoginHelper.getUserId();
        vo.setUserId(userId);
        return R.ok(userCameraAuditService.uploadCameraAudit(vo));
    }

    @Operation(summary = "同意主播服务协议")
    @PostMapping("/agreeProtocol")
    public R<Boolean> agreeProtocol(){
        boolean b = userService.agreeProtocol(LoginHelper.getUserId());
        return R.ok(b);
    }

    @Operation(summary = "加入主播页面")
    @GetMapping("/joinHome")
    public R<AnchorJoinHomeVo> joinHome(){
        AnchorJoinHomeVo vo = anchorApplyService.joinHome(LoginHelper.getUserId());
        return R.ok(vo);
    }

    @Operation(summary = "申请加入主播")
    @GetMapping("/joinAnchor")
    public R<Boolean> joinAnchor(){
        return R.ok(anchorApplyService.joinAnchor(LoginHelper.getUserId()));
    }


}
