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.ProductResourceAllocationApi;
import com.ikon.projectmanagement.dto.request.ProductPSResourceAllocationRequestDto;
import com.ikon.projectmanagement.dto.response.ProductPSResourceAllocationResponseDto;
import com.ikon.projectmanagement.service.ProductResourceAllocationService;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
public class ProductResourceAllocationController implements ProductResourceAllocationApi {

    private final ProductResourceAllocationService allocationService;

    @Override
    public ResponseEntity<List<ProductPSResourceAllocationResponseDto>> getResourceAllocations(
            String accessToken,
            UUID productIdentifier) {
        return ResponseEntity.ok(allocationService.getResourceAllocations(productIdentifier));
    }

    @Override
    public ResponseEntity<ProductPSResourceAllocationResponseDto> getResourceAllocation(
            String accessToken,
            UUID productIdentifier,
            UUID allocationIdentifier) {
        return ResponseEntity.ok(allocationService.getResourceAllocation(productIdentifier, allocationIdentifier));
    }

    @Override
    public ResponseEntity<ProductPSResourceAllocationResponseDto> createResourceAllocation(
            String accessToken,
            UUID productIdentifier,
            ProductPSResourceAllocationRequestDto allocationRequestDto) {
        return ResponseEntity.status(201).body(allocationService.createResourceAllocation(productIdentifier, allocationRequestDto));
    }

    @Override
    public ResponseEntity<ProductPSResourceAllocationResponseDto> updateResourceAllocation(
            String accessToken,
            UUID productIdentifier,
            UUID allocationIdentifier,
            ProductPSResourceAllocationRequestDto allocationRequestDto) {
        return ResponseEntity.ok(allocationService.updateResourceAllocation(productIdentifier, allocationIdentifier, allocationRequestDto));
    }

    @Override
    public ResponseEntity<Void> deleteResourceAllocation(
            String accessToken,
            UUID productIdentifier,
            UUID allocationIdentifier) {
        allocationService.deleteResourceAllocation(productIdentifier, allocationIdentifier);
        return ResponseEntity.noContent().build();
    }
}
