package gaf3.core.gateway

import org.springframework.core.io.ClassPathResource
import org.springframework.core.io.Resource
import org.springframework.http.HttpStatus
import org.springframework.http.server.reactive.ServerHttpResponse
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.ResponseBody
import reactor.core.publisher.Mono

@Controller
class GatewayController {
    @RequestMapping(value = ["/401"])
    @ResponseBody
    fun status401(res: ServerHttpResponse): Mono<String> {
        res.statusCode = HttpStatus.UNAUTHORIZED
        return Mono.just("No Authorization!")
    }

    @GetMapping(path = ["/mock/menu/items"])
    @ResponseBody
    fun items(res: ServerHttpResponse): Resource {
        res.headers["content-type"] = "text/plain; charset=utf-8"
        return ClassPathResource("/menu/items_res.json")
    }
    @GetMapping(path = ["/mock/menu/menus"])
    @ResponseBody
    fun menus(res: ServerHttpResponse): Resource {
        res.headers["content-type"] = "application/json; charset=utf-8"
        return ClassPathResource("/menu/menus_res.json")
    }
    @GetMapping(path = ["/mock/code/{type}/items"])
    @ResponseBody
    fun codes(@PathVariable type: String, res: ServerHttpResponse): Resource {
        res.headers["content-type"] = "text/plain; charset=utf-8"
        return ClassPathResource("/code/${type}.json")
    }
}