package com.caliverse.admin.domain.api;

import java.util.Map;

import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
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.PathVariable;
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.BlackListRequest;
import com.caliverse.admin.domain.response.BlackListResponse;
import com.caliverse.admin.domain.service.BlackListService;

import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

@Tag(name = "이용자 제재 조회", description = "이용자 제재 메뉴 api 입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/black-list")
public class BlackListController {
    private final BlackListService blackListService;
    //이용자 제재 조회 리스트
    @GetMapping("/list")
    public ResponseEntity<BlackListResponse> getUserBlackList(
            @RequestParam Map<String, String> requestParams){
        return ResponseEntity.ok().body( blackListService.getBlackList(requestParams));
    }

    @GetMapping("/detail/{id}")
    public ResponseEntity<BlackListResponse> getBlackListDetail(
            @PathVariable("id") Long id){
        return ResponseEntity.ok().body( blackListService.getBlackListDetail(id));
    }
    @PostMapping
    public ResponseEntity<BlackListResponse> postBlackList(
            @RequestBody BlackListRequest blackListRequest){
        return ResponseEntity.ok().body( blackListService.postBlackList(blackListRequest));
    }
    @PostMapping("/excel-upload")
    public ResponseEntity<BlackListResponse> excelUpload(
            @RequestParam("file") MultipartFile file){
        return ResponseEntity.ok().body( blackListService.excelUpload(file));
    }

    @GetMapping("/excel-down")
    public ResponseEntity<Resource> excelDown(
            @RequestParam("file") String fileName){
        Resource resource = blackListService.excelDown(fileName);
        HttpHeaders headers = new HttpHeaders();
        headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + fileName);

        return ResponseEntity.ok()
                .headers(headers)
                .body(resource);
    }

    @DeleteMapping
    public ResponseEntity<BlackListResponse> deleteBlackList(
            @RequestBody BlackListRequest blackListRequest){
        return ResponseEntity.ok().body( blackListService.deleteBlackList(blackListRequest));
    }
}
