package com.micer.easyball.controller;

import com.micer.easyball.ApiVersion;

import com.micer.easyball.pojo.Club;
import com.micer.easyball.pojo.ResponseResult;
import com.micer.easyball.service.ClubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(ApiVersion.V1)
public class ClubController {
    @Autowired
    private ClubService clubService;

    /**
     * 新增俱乐部
     * @param club
     */
    @PreAuthorize("@ex.hasRole('ROLE_ADMIN')")
    @PostMapping("/club/addclub")
    public ResponseResult addClub(@RequestBody Club club)
    {
        return clubService.addClub(club);
    }

    /**
     * 获取俱乐部中所有球员
     */
    @PreAuthorize("@ex.hasRole('ROLE_CLUB_PLAYER')")
    @GetMapping("/club/getPlayers")
    public ResponseResult getPlayers()
    {
        return clubService.getPlayers();
    }

    /**
     * 配置并测试 Webhook (API7 SSRF 漏洞靶标)
     */
    @PostMapping("/club/testWebhook")
    @PreAuthorize("@ex.hasRole('ROLE_CLUB_ADMIN')")
    public ResponseResult testWebhook(@RequestParam String webhookUrl) {
        return clubService.testWebhook(webhookUrl);
    }

}
