package com.thesis.centralserver.controllers;

import com.thesis.centralserver.dtos.OffloadingTaskDTO;
import com.thesis.centralserver.entities.mappers.OffloadingTaskMapper;
import com.thesis.centralserver.services.OffloadingTaskService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/tasks")
public class OffloadingTaskController {

    private final OffloadingTaskService offloadingTaskService;

    public OffloadingTaskController(OffloadingTaskService offloadingTaskService) {
        this.offloadingTaskService = offloadingTaskService;
    }

    @GetMapping("/")
    public List<OffloadingTaskDTO> getAllTasks() {
        return OffloadingTaskMapper.createTaskDTOList(offloadingTaskService.getAllTasks());
    }

    @PostMapping("/{id}/completed")
    public OffloadingTaskDTO markCompleted(@Valid @PathVariable Long id) {
        return OffloadingTaskMapper.createTaskDTO(offloadingTaskService.markTaskCompleted(id));
    }

    @PostMapping("/{id}/failed")
    public OffloadingTaskDTO markFailed(@Valid @PathVariable Long id) {
        return OffloadingTaskMapper.createTaskDTO(offloadingTaskService.markTaskFailed(id));
    }

}
