package com.ikon.projectmanagement.controller;

import com.ikon.projectmanagement.api.RiskApi;
import com.ikon.projectmanagement.dto.request.RiskCreateRequestDto;
import com.ikon.projectmanagement.dto.response.RiskResponseDto;
import com.ikon.projectmanagement.service.RiskService;

import java.util.List;
import java.util.UUID;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class RiskController implements RiskApi {

        private final RiskService riskService;

        @Override
        public ResponseEntity<RiskResponseDto> createRisk(
                        String accessToken,
                        RiskCreateRequestDto riskCreateRequestDto) {

                RiskResponseDto createdRisk = riskService.createRisk(riskCreateRequestDto);

                return ResponseEntity
                                .status(HttpStatus.CREATED)
                                .body(createdRisk);
        }

        @Override
        public ResponseEntity<List<RiskResponseDto>> getAllRisks(
                        String accessToken) {

                return ResponseEntity.ok(
                                riskService.getAllRisks());
        }

        @Override
        public ResponseEntity<RiskResponseDto> getRiskById(
                        String accessToken,
                        UUID riskId) {

                return ResponseEntity.ok(
                                riskService.getRiskById(riskId));
        }

        @Override
        public ResponseEntity<RiskResponseDto> updateRisk(
                        String accessToken,
                        UUID riskId,
                        RiskCreateRequestDto riskCreateRequestDto) {

                return ResponseEntity.ok(
                                riskService.updateRisk(riskId, riskCreateRequestDto));
        }

        @Override
        public ResponseEntity<List<RiskResponseDto>> getRisksByProject(
                        String accessToken,
                        String projectIdentifier) {

                return ResponseEntity.ok(
                                riskService.getRisksByProject(projectIdentifier));
        }

       
}