package com.ikon.projectmanagement.api;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;

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

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

import com.ikon.projectmanagement.dto.request.ProductOfProjectRequestDto;
import com.ikon.projectmanagement.dto.request.WorkflowTransitionRequestDto;
import com.ikon.projectmanagement.dto.response.ProductOfProjectResponseDto;

@Tag(name = "Product APIs", description = "Product Of Project Management related APIs")
@RequestMapping("/api/v1/projects")
public interface ProductOfProjectApi {

        @Operation(summary = "Get all products", description = "Retrieves a list of all existing products.", responses = {
                        @ApiResponse(responseCode = "200", description = "Products retrieved successfully"),
                        @ApiResponse(responseCode = "401", description = "Unauthorized"),
                        @ApiResponse(responseCode = "500", description = "Internal server error")
        })
        @GetMapping("/{projectIdentifier}/products")
        ResponseEntity<List<ProductOfProjectResponseDto>> getAllProductsByProject(
                        @RequestHeader("Authorization") String accessToken,
                        @PathVariable("projectIdentifier") UUID projectIdentifier);

        @Operation(summary = "Get product by product identifier", description = "Retrieves a single product under a project (account + project scoped).", responses = {
                        @ApiResponse(responseCode = "200", description = "Product retrieved successfully"),
                        @ApiResponse(responseCode = "401", description = "Unauthorized"),
                        @ApiResponse(responseCode = "404", description = "Product not found"),
                        @ApiResponse(responseCode = "500", description = "Internal server error")
        })
        @GetMapping("/{projectIdentifier}/products/{productIdentifier}")
        ResponseEntity<ProductOfProjectResponseDto> getProductById(
                        @RequestHeader("Authorization") String accessToken,
                        @PathVariable("projectIdentifier") UUID projectIdentifier,
                        @PathVariable("productIdentifier") UUID productIdentifier);

        // ================= UPDATE PRODUCT =================
        @Operation(summary = "Update an existing product", description = "Updates a product under a specific project (secure multi-tenant update).", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "Updated product details", required = true, content = @Content(schema = @Schema(implementation = ProductOfProjectRequestDto.class))), responses = {
                        @ApiResponse(responseCode = "200", description = "Product updated successfully"),
                        @ApiResponse(responseCode = "400", description = "Invalid product data"),
                        @ApiResponse(responseCode = "401", description = "Unauthorized"),
                        @ApiResponse(responseCode = "404", description = "Product not found"),
                        @ApiResponse(responseCode = "500", description = "Internal server error")
        })
        @PutMapping("/{projectIdentifier}/products/{productIdentifier}")
        ResponseEntity<ProductOfProjectResponseDto> updateProduct(
                        @RequestHeader("Authorization") String accessToken,
                        @PathVariable("projectIdentifier") UUID projectIdentifier,
                        @PathVariable("productIdentifier") UUID productIdentifier,
                        @RequestBody ProductOfProjectRequestDto productDto);

        // ================= WORKFLOW STAGE TRANSITION =================
        @Operation(summary = "Transition product workflow stage", description = "Transitions the product to a new workflow stage with validation. The Schedule → Resources & Expenses transition requires schedule data to exist.", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "Transition request with target status", required = true, content = @Content(schema = @Schema(implementation = WorkflowTransitionRequestDto.class))), responses = {
                        @ApiResponse(responseCode = "200", description = "Transition successful"),
                        @ApiResponse(responseCode = "400", description = "Transition not allowed or preconditions not met"),
                        @ApiResponse(responseCode = "401", description = "Unauthorized"),
                        @ApiResponse(responseCode = "404", description = "Product not found"),
                        @ApiResponse(responseCode = "500", description = "Internal server error")
        })
        @PostMapping("/{projectIdentifier}/products/{productIdentifier}/transition")
        ResponseEntity<ProductOfProjectResponseDto> transitionProductStatus(
                        @RequestHeader("Authorization") String accessToken,
                        @PathVariable("projectIdentifier") UUID projectIdentifier,
                        @PathVariable("productIdentifier") UUID productIdentifier,
                        @RequestBody WorkflowTransitionRequestDto transitionDto);
}
