package com.its.web.controller.common;

import com.its.web.dto.common.ConnStatisticsDto;
import com.its.web.dto.common.TbWwwOrgDto;
import com.its.web.service.common.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Nullable;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/common")
@Api(tags = "00.공통")
public class CommonController {

    private final CommonService service;

    @ApiOperation(value = "공공기관 웹사이트 조회(TB_WWW_ORGAN)", response = TbWwwOrgDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/web-organ", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public List<TbWwwOrgDto> findAllOrganization() { return this.service.findAllOrganization(); }

    @ApiOperation(value = "접속자 통계(TB_WWW_CONN_HS)", response = ConnStatisticsDto.class, responseContainer = "ArrayList")
    @PostMapping(value = "/conn-statistics", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public List<ConnStatisticsDto> getConnStatistics(@Nullable @RequestParam Map<String, String> paramMap) {return this.service.getConnStatistics(paramMap);}

    @ApiOperation(value = "에디터 게시물 이미지 업로드")
    @PostMapping(value = "/image-upload")
    @ResponseBody
    public String noticeImageUpload(HttpServletRequest req) {
        return this.service.imageUpload(req);
    }

    @ApiOperation(value= "업로드 이미지 소스 가져오기")
    @GetMapping(value="/upload/{imageName}")
    @ResponseBody
    public byte[] getImage(@PathVariable("imageName") String imageName) {
        return this.service.getImage(imageName);
    }
}
