package com.zsElectric.boot.auth.controller;

import com.zsElectric.boot.core.web.Result;
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.web.bind.annotation.*;

/**
 * 安全测试控制器
 * <p>
 * 用于测试 XSS 和 SQL 注入防护功能
 *
 * @author zsElectric
 */
@Tag(name = "安全测试接口", description = "用于测试 XSS 和 SQL 注入防护功能")
@RestController
@RequestMapping("/api/v1/security/test")
@RequiredArgsConstructor
@Slf4j
public class SecurityTestController {

    @Operation(summary = "测试 XSS 防护", description = "测试 XSS 攻击防护功能")
    @PostMapping("/xss")
    public Result<String> testXss(@RequestBody TestRequest request) {
        log.info("收到 XSS 测试请求: {}", request.getContent());
        return Result.success("XSS 测试成功，内容: " + request.getContent());
    }

    @Operation(summary = "测试 SQL 注入防护", description = "测试 SQL 注入防护功能")
    @PostMapping("/sql-injection")
    public Result<String> testSqlInjection(@RequestBody TestRequest request) {
        log.info("收到 SQL 注入测试请求: {}", request.getContent());
        return Result.success("SQL 注入测试成功，内容: " + request.getContent());
    }

    @Operation(summary = "测试查询参数", description = "测试查询参数的 XSS 和 SQL 注入防护")
    @GetMapping("/query")
    public Result<String> testQueryParams(@RequestParam String param) {
        log.info("收到查询参数测试请求: {}", param);
        return Result.success("查询参数测试成功，内容: " + param);
    }

    /**
     * 测试请求对象
     */
    public static class TestRequest {
        private String content;

        public String getContent() {
            return content;
        }

        public void setContent(String content) {
            this.content = content;
        }
    }
}
