package com.caliverse.admin.domain.api;

import java.util.Map;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.caliverse.admin.domain.request.WhiteListRequest;
import com.caliverse.admin.domain.response.WhiteListResponse;
import com.caliverse.admin.domain.service.WhiteListService;

import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;

@Tag(name = "화이트리스트", description = "화이트리스트 메뉴 api 입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/white-list")
public class WhiteListController {
    private final WhiteListService whiteListService;
    //화이트 리스트 명단 조회
    @GetMapping("/list")
    public ResponseEntity<WhiteListResponse> getWhiteList(
            @RequestParam Map<String, String> requestParams){
        return ResponseEntity.ok().body( whiteListService.getWhiteList(requestParams));
    }


    // 화이트리스트 일광 등록 (엑셀 업로드)
    @PostMapping("/excel-upload")
    public ResponseEntity<WhiteListResponse> excelUpload(
            @RequestParam("file") MultipartFile file){
        return ResponseEntity.ok().body( whiteListService.excelUpload(file));
    }

    // 화이트리스트 단일 등록
    @PostMapping
    public ResponseEntity<WhiteListResponse> postWhiteList(
            @RequestBody WhiteListRequest whiteListRequest){
        return ResponseEntity.ok().body( whiteListService.postWhiteList(whiteListRequest));
    }
    // 화이트리스트 복수 등록
    @PostMapping("/multiPost")
    public ResponseEntity<WhiteListResponse> multiPost(
            @RequestParam("file") MultipartFile file){
        return ResponseEntity.ok().body( whiteListService.multiPost(file));
    }
    @GetMapping("/excelDownLoad")
    public void excelDownLoad(HttpServletResponse res){
        whiteListService.excelDownLoad(res);
    }
    // 화이트리스트 승인
    @PatchMapping
    public ResponseEntity<WhiteListResponse> updateWhiteList(
            @RequestBody WhiteListRequest whiteListRequest){
        return ResponseEntity.ok().body(whiteListService.updateWhiteList(whiteListRequest));
    }

    @DeleteMapping
    public ResponseEntity<WhiteListResponse> deleteWhiteList(
            @RequestBody WhiteListRequest whiteListRequest){
        return ResponseEntity.ok().body(whiteListService.deleteWhiteList(whiteListRequest));
    }
}
