package com.malk.mc.controller;

import com.malk.mc.service.McRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/request")
@RestController
public class McRequestController {
    @Autowired
    private McRequestService mcRequestService;

    @PostMapping("/get")
    public Map get(@RequestBody Map map) {
        String url = map.get("url").toString();
        Map headers = (Map) map.get("headers");
        Map params = (Map) map.get("params");

        return mcRequestService.get(url, headers, params);
    }

    @PostMapping("/post")
    public Map post(@RequestBody Map map) {
        String url = map.get("url").toString();
        Map headers = (Map) map.get("headers");
        Map params = (Map) map.get("params");
        Map body = (Map) map.get("body");

        return mcRequestService.post(url, headers, params, body);
    }

    @PostMapping("/downloadFile")
    public String downloadFile(@RequestBody Map map) {
        String url = map.get("url").toString();
        Map headers = (Map) map.get("headers");
        Map params = (Map) map.get("params");
        String fileName = map.get("fileName").toString();
        String downloadPath = map.get("downloadPath").toString();
        return mcRequestService.downloadFile(url,headers, params, fileName,downloadPath);
    }
}
