package com.ikon.projectmanagement.controller;

import com.ikon.projectmanagement.api.ProjectApi;
import com.ikon.projectmanagement.dto.request.ProjectRequestDto;
import com.ikon.projectmanagement.dto.response.ProjectResponseDto;
import com.ikon.projectmanagement.dto.response.ProjectTimelineResponseDto;
import com.ikon.projectmanagement.service.ProjectService;

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 ProjectController implements ProjectApi {

        private final ProjectService projectService;

        @Override
        public ResponseEntity<ProjectResponseDto> createProject(
                        String accessToken,
                        ProjectRequestDto projectRequestDto) {

                ProjectResponseDto createdProject = projectService.createProject(projectRequestDto);

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

        @Override
        public ResponseEntity<List<ProjectResponseDto>> getAllProjects(
                        String accessToken) {

                return ResponseEntity.ok(
                                projectService.getAllProjects());
        }

        @Override
        public ResponseEntity<ProjectResponseDto> getProjectByProjectIdentifier(String accessToken,
                        UUID projectIdentifier) {

                return ResponseEntity.ok(projectService.getProjectByProjectIdentifier(projectIdentifier));
        }

        @Override
        public ResponseEntity<ProjectResponseDto> updateProject(
                        String accessToken,
                        UUID projectIdentifier,
                        ProjectRequestDto projectDto) {

                return ResponseEntity.ok(
                                projectService.updateProject(projectIdentifier, projectDto));
        }

        @Override
        public ResponseEntity<List<ProjectTimelineResponseDto>> getAllActiveProjectsTimeline(
                        String accessToken) {

                return ResponseEntity.ok(projectService.getAllActiveProjectsTimeline());
        }
}
