package com.its.web.controller.popup;

import com.its.web.dto.notice.AttachFileDto;
import com.its.web.service.popup.PopupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/popup")
@Api(tags = "00.팝업")
public class popupController {
    private final PopupService service;

    @ApiOperation(value = "01.팝업 글쓰기")
    @PostMapping(value= {"/writePopup", }, produces = {"application/json; charset=utf8"})
    @ResponseBody
    public Map<String, String> writePopup(@RequestParam Map<String, String> paramMap, MultipartFile attachFile) {
        return this.service.writePopup(paramMap, attachFile);
    }

    @ApiOperation(value = "02.팝업 이미지 다운")
    @PostMapping(value = "/attach", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public AttachFileDto downloadAttach(@Param("imgId") String imgId, @Param("imgName") String imgName) {
        return this.service.downloadAttach(imgId, imgName);
    }

    @ApiOperation(value= "03.팝업 글수정")
    @PostMapping(value = "/modifyPopup", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public Map<String, String> modifyPopup(@RequestParam Map<String, String> paramMap, MultipartFile attachFile) {
        return this.service.modifyPopup(paramMap, attachFile);
    }

    @ApiOperation(value= "03.팝업 글삭제")
    @PostMapping(value = "/deletePopup", produces = {"application/json; charset=utf8"})
    @ResponseBody
    public Map<String, String> deletePopup(@Param("popupId") String popupId) {
        return this.service.deletePopup(popupId);
    }
}
