package com.ikon.projectmanagement.controller;

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

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;

import com.ikon.projectmanagement.api.ProductOfProjectApi;
import com.ikon.projectmanagement.dto.request.ProductOfProjectRequestDto;
import com.ikon.projectmanagement.dto.request.WorkflowTransitionRequestDto;
import com.ikon.projectmanagement.dto.response.ProductOfProjectResponseDto;
import com.ikon.projectmanagement.service.ProductOfProjectService;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
public class ProductOfProjectController implements ProductOfProjectApi {

        private final ProductOfProjectService productOfProjectService;

        @Override
        public ResponseEntity<List<ProductOfProjectResponseDto>> getAllProductsByProject(
                        String accessToken,
                        UUID projectIdentifier) {

                return ResponseEntity.ok(
                                productOfProjectService.getProductsByProject(projectIdentifier));
        }

        @Override
        public ResponseEntity<ProductOfProjectResponseDto> getProductById(
                        String accessToken,
                        UUID projectIdentifier,
                        UUID productIdentifier) {

                return ResponseEntity.ok(
                                productOfProjectService.getProduct(projectIdentifier, productIdentifier));
        }

        @Override
        public ResponseEntity<ProductOfProjectResponseDto> updateProduct(
                        String accessToken,
                        UUID projectIdentifier,
                        UUID productIdentifier,
                        ProductOfProjectRequestDto productDto) {

                return ResponseEntity.ok(
                                productOfProjectService.updateProduct(projectIdentifier, productIdentifier,
                                                productDto));
        }

        @Override
        public ResponseEntity<ProductOfProjectResponseDto> transitionProductStatus(
                        String accessToken,
                        UUID projectIdentifier,
                        UUID productIdentifier,
                        WorkflowTransitionRequestDto transitionDto) {

                return ResponseEntity.ok(
                                productOfProjectService.transitionStatus(
                                                projectIdentifier,
                                                productIdentifier,
                                                transitionDto.getTargetStatus()));
        }
}
