package com.xindazhou.business.controller.app.community.follow;

import com.xindazhou.business.service.community.follow.FollowService;
import com.xindazhou.framework.common.pojo.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static com.xindazhou.framework.common.pojo.CommonResult.success;

/**
 * 移动端 - 关注 Controller
 *
 * @author xindazhou
 */
@Tag(name = "移动端 - 关注管理")
@RestController
@RequestMapping("/app-api/community/follow")
@Validated
@Slf4j
public class FollowController {

    @Resource
    private FollowService followService;

    @PostMapping("/toggle")
    @Operation(summary = "关注/取消关注")
    @Parameter(name = "followUserId", description = "关注的用户ID", required = true, example = "1")
    public CommonResult<Boolean> toggleFollow(@RequestParam("followUserId") Long followUserId) {
        Boolean isFollowed = followService.toggleFollow(followUserId);
        return success(isFollowed);
    }

    @GetMapping("/check")
    @Operation(summary = "查询是否已关注")
    @Parameter(name = "followUserId", description = "关注的用户ID", required = true, example = "1")
    public CommonResult<Boolean> isFollowed(@RequestParam("followUserId") Long followUserId) {
        Boolean isFollowed = followService.isFollowed(followUserId);
        return success(isFollowed);
    }

    @GetMapping("/count")
    @Operation(summary = "统计关注数")
    @Parameter(name = "userId", description = "用户ID", required = true, example = "1")
    public CommonResult<Long> getFollowCount(@RequestParam("userId") Long userId) {
        Long count = followService.getFollowCount(userId);
        return success(count);
    }

    @GetMapping("/fans-count")
    @Operation(summary = "统计粉丝数")
    @Parameter(name = "userId", description = "用户ID", required = true, example = "1")
    public CommonResult<Long> getFansCount(@RequestParam("userId") Long userId) {
        Long count = followService.getFansCount(userId);
        return success(count);
    }

}

