package com.test.musichouduan.controller.admin;

import cn.dev33.satoken.annotation.SaCheckRole;
import com.test.musichouduan.dto.CommentDTO;
import com.test.musichouduan.dto.PageResult;
import com.test.musichouduan.dto.Result;
import com.test.musichouduan.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 管理员评论控制器
 */
@Tag(name = "管理员评论接口", description = "提供管理员评论管理功能")
@RestController
@RequestMapping("/api/admin/comment")
@SaCheckRole("admin")
public class AdminCommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 分页获取所有评论
     *
     * @param page 页码
     * @param size 每页大小
     * @param keyword 关键字
     * @param targetType 目标类型
     * @param status 状态
     * @return 响应结果
     */
    @Operation(summary = "分页获取所有评论", description = "管理员分页获取所有评论")
    @GetMapping("/list")
    public Result<PageResult<CommentDTO>> getCommentList(
            @Parameter(description = "页码", example = "1") @RequestParam(defaultValue = "1") Integer page,
            @Parameter(description = "每页大小", example = "10") @RequestParam(defaultValue = "10") Integer size,
            @Parameter(description = "关键字") @RequestParam(required = false) String keyword,
            @Parameter(description = "目标类型：1-音乐，2-歌单，3-歌手") @RequestParam(required = false) Integer targetType,
            @Parameter(description = "状态：0-禁用，1-正常") @RequestParam(required = false) Integer status) {
        PageResult<CommentDTO> pageResult = commentService.getAdminCommentList(page, size, keyword, targetType, status);
        return Result.success(pageResult);
    }

    /**
     * 更新评论状态
     *
     * @param id 评论ID
     * @param status 状态：0-禁用，1-正常
     * @return 响应结果
     */
    @Operation(summary = "更新评论状态", description = "管理员更新评论状态")
    @PutMapping("/{id}/status")
    public Result<Boolean> updateCommentStatus(
            @Parameter(description = "评论ID") @PathVariable Long id,
            @Parameter(description = "状态：0-禁用，1-正常", example = "1") @RequestParam Integer status) {
        boolean result = commentService.updateCommentStatus(id, status);
        return Result.success("更新成功", result);
    }

    /**
     * 删除评论
     *
     * @param id 评论ID
     * @return 响应结果
     */
    @Operation(summary = "删除评论", description = "管理员删除评论")
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteComment(@Parameter(description = "评论ID") @PathVariable Long id) {
        boolean result = commentService.adminDeleteComment(id);
        return Result.success("删除成功", result);
    }
}
