package com.kospo.talk.controller;

import com.kospo.talk.config.exception.CustomErrorResponse;
import com.kospo.talk.payload.AutoReplyDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.Principal;
import java.util.HashMap;

@RestController
@Tag(name = "Service Api", description = "서비스 관리")
@RequestMapping("/api")
@RequiredArgsConstructor
public class SerivceController {

    @Operation(summary = "현재 접속 ap 조회", description = "현재 접속 서비스 확인")
    @ApiResponses({
            @ApiResponse(description = "Success", responseCode = "200",
                    content = @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", schema = @Schema(oneOf =
                            {String.class})
                    )),
            @ApiResponse(description = "Not found", responseCode = "404",
                    content = @io.swagger.v3.oas.annotations.media.Content(mediaType = "text/plain", schema = @Schema(oneOf =
                            {String.class}))),
            @ApiResponse(description = "Internal Error", responseCode = "500",
                    content = @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", schema = @Schema(oneOf =
                            {CustomErrorResponse.class })))
    })
    @GetMapping("/getApInfo")
    public ResponseEntity findAll(
            HttpServletRequest request,
            Principal principal
    ) {
        HashMap<String, String> map = new HashMap<>();
        try {
            String ip = InetAddress.getLocalHost().getHostAddress();
            if(ip.equals("10.130.7.62")) {
                map.put("server", "ap1");
            } else if(ip.equals("10.130.7.63")) {
                map.put("server", "ap2");
            } else if(ip.equals("10.130.7.64")) {
                map.put("server", "ap3");
            } else if(ip.equals("10.130.7.65")) {
                map.put("server", "ap4");
            } else if(ip.equals("10.130.7.61")) {
                map.put("server", "ma");
            } else {
                map.put("server", "local");
            }
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
        return ResponseEntity.ok(map);
    }
}
