package com.royalrangers.controller.achievement;

import com.dropbox.core.DbxException;
import com.royalrangers.dto.ResponseResult;
import com.royalrangers.dto.achievement.AchievementRequestDto;
import com.royalrangers.enums.ImageType;
import com.royalrangers.service.DropboxService;
import com.royalrangers.service.achievement.QuarterAchievementService;
import com.royalrangers.utils.ResponseBuilder;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@RestController
@RequestMapping("/achievements/quarter")
public class QuarterAchievementController {

    @Autowired
    private QuarterAchievementService quarterAchievementService;

    @Autowired
    private DropboxService dropboxService;

    @GetMapping
    public ResponseResult getAllQuarterAchievement() {
        try {
            return ResponseBuilder.success(quarterAchievementService.getAllQuarterAchievement());
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return ResponseBuilder.fail("Failed added QuarterAchievement");
        }
    }

    @PostMapping
    public ResponseResult addQuarterAchievement(@RequestBody AchievementRequestDto params) {
        try {
            quarterAchievementService.addQuarterAchievement(params);
            return ResponseBuilder.success("Adding QuarterAchievement was a success");
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return ResponseBuilder.fail("Failed added QuarterAchievement");
        }
    }

    @GetMapping("/{quarterId}")
    public ResponseResult getQuarterAchievementById(@PathVariable Long quarterId) {
        try {
            return ResponseBuilder.success(quarterAchievementService.getQuarterAchievementById(quarterId));
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return ResponseBuilder.fail("Failed get QuarterAchievement by id");
        }
    }

    @DeleteMapping("/{quarterId}")
    public ResponseResult deleteQuarterAchievement(@PathVariable Long quarterId) {
        try {
            quarterAchievementService.deleteQuarterAchievement(quarterId);
            return ResponseBuilder.success("Delete QuarterAchievement was a success");
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return ResponseBuilder.fail("Failed deleted QuarterAchievement");
        }
    }

    @PutMapping("/{quarterId}")
    public ResponseResult editQuarterAchievement(@RequestBody AchievementRequestDto params, @PathVariable Long quarterId) {
        try {
            return ResponseBuilder.success(quarterAchievementService.editQuarterAchievement(params, quarterId));
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return ResponseBuilder.fail("Failed edit QuarterAchievement");
        }
    }

    @PostMapping("/logo")
    @ApiOperation(value = "Upload and set quarter achievement logo")
    public ResponseResult uploadLogo(@RequestParam("quarterId") Long quarterId, @RequestParam("file") MultipartFile file) {
        try {
            String logoUrl = dropboxService.imageUpload(file, ImageType.QUARTER_ACHIEVEMENT_LOGO);
            quarterAchievementService.setLogoUrl(logoUrl, quarterId);
            return ResponseBuilder.success("LogoUrl", logoUrl);
        } catch (IOException | DbxException e) {
            return ResponseBuilder.fail(e.getMessage());
        }
    }

    @DeleteMapping("/logo")
    @ApiOperation(value = "Delete quarter achievement logo")
    public ResponseResult delete(@RequestParam("quarterId") Long quarterId) {
        try {
            quarterAchievementService.deleteLogo(quarterId);
            return ResponseBuilder.success("Logo deleted.");

        } catch (DbxException e) {
            return ResponseBuilder.fail(e.getMessage());
        }
    }

}
@@ -929,32 +929,90 @@
     @GetMapping%0A
+    @ApiOperation(value = %22Get all quarter achievements%22)%0A
     public Respo
@@ -1046,24 +1046,24 @@
 evement() %7B%0A
-
         try 
@@ -1320,32 +1320,125 @@
        %7D%0A    %7D%0A%0A
+    @ApiOperation(value = %22Add quarter achievement related to year achievement (upLevelId)%22)%0A
     @PostMapping
@@ -1891,32 +1891,91 @@
 %22/%7BquarterId%7D%22)%0A
+    @ApiOperation(value = %22Get quarter achievement by id%22)%0A
     public Respo
@@ -2361,32 +2361,94 @@
 %22/%7BquarterId%7D%22)%0A
+    @ApiOperation(value = %22Delete quarter achievement by id%22)%0A
     public Respo
@@ -2854,24 +2854,24 @@
    %7D%0A    %7D%0A%0A
-
     @PutMapp
@@ -2886,24 +2886,86 @@
 uarterId%7D%22)%0A
+    @ApiOperation(value = %22Update quarter achievement by id%22)%0A
     public R

Add API descriptions for QuarterAchievementController