package top.awin_x.learn.controller;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import top.awin_x.learn.pojo.CourseInfo;
import top.awin_x.learn.pojo.Result;

import java.util.ArrayList;

@RestController
@RequestMapping("/test")
public class HelloController {
    @GetMapping("/hello1")
    public String hello() {
        System.out.println("Hello World");
        return "Hello World";
    }

    @GetMapping("/helloWithParam")
    public String helloWithParam(HttpServletRequest request) {
        String name = request.getParameter("name");
        return "Hello " + name;
    }

    @GetMapping("/helloWithParam2")
    public String helloWithParam2(String name, Integer age) {
        return "Hello " + name + " " + age;
    }

    @GetMapping("/helloWithParam3")
    public String helloWithParam3(CourseInfo courseInfo) {
        System.out.println(courseInfo);
        return "Hello " + courseInfo.getName();
    }

    @GetMapping("/helloWithJSON")
    public String helloWithJSON(@RequestBody CourseInfo courseInfo) {
        System.out.println(courseInfo);
        return "Hello " + courseInfo.getName();
    }

    @GetMapping("/helloWithPath/{name}")
    public String helloWithPath(@PathVariable String name) {
        return "Hello " + name;
    }

    @GetMapping("/helloWithResultReturn")
    public Result helloWithResultReturn(String name) {
        Result result = new Result();
        ArrayList<String> list = new ArrayList<>();
        list.add(name);
        result.setData(list);
        result.setMsg("Hello " + name);
        result.setSuccess(true);
        return result;
    }


}
