package com.dowstats.controllers

import com.dowstats.service.integrations.ModStorageIntegrationService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile


@RestController
@RequestMapping("api/v1/custom-mod")
class CustomModsController @Autowired constructor(
    val modStorageIntegrationService: ModStorageIntegrationService
) {

    @PostMapping("/reload/{modId}")
    fun reloadMod(@PathVariable modId: Long): String {
        modStorageIntegrationService.reloadMod(modId)
        return "Successfully reload mod"
    }

    @DeleteMapping("/data")
    fun deleteAllModData(): String {
        modStorageIntegrationService.deleteMods()
        return "Successfully delete all mods data"
    }

    @DeleteMapping("/data/{modId}")
    fun deleteModData(@PathVariable modId: Long): String {
        modStorageIntegrationService.deleteMod(modId)
        return "Successfully delete mod data"
    }

    @PostMapping("/upload")
    fun uploadMod(@RequestParam("file") file: MultipartFile?,
                  @RequestParam("name") name: String,
                  @RequestParam("technicalName") technicalName: String,
                  @RequestParam("version") version: String?): String {
        modStorageIntegrationService.saveModFromRequest(file, name, technicalName, version?:"1.0.0")
        return "Successfully upload mod"
    }
}