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.IssueCreateRequestDto;
import com.ikon.projectmanagement.dto.response.IssueResponseDto;

@Tag(name = "Issue APIs", description = "Issue Management related APIs")
@RequestMapping("/api/v1/issues")
public interface IssueApi {

    // ================= CREATE =================

    @Operation(summary = "Create a new issue", description = "Creates a new issue and returns the created issue details.", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "Issue details", required = true, content = @Content(schema = @Schema(implementation = IssueCreateRequestDto.class))), responses = {
            @ApiResponse(responseCode = "201", description = "Issue created successfully"),
            @ApiResponse(responseCode = "400", description = "Invalid issue data"),
            @ApiResponse(responseCode = "401", description = "Unauthorized"),
            @ApiResponse(responseCode = "500", description = "Internal server error")
    })
    @PostMapping
    ResponseEntity<IssueResponseDto> createIssue(
            @RequestHeader("Authorization") String accessToken,
            @RequestBody IssueCreateRequestDto issueCreateRequestDto);

    // ================= READ ALL =================

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


    // ================= READ BY ID =================

    @Operation(summary = "Get issue by ID", description = "Retrieves an issue by its unique issue ID.", responses = {
            @ApiResponse(responseCode = "200", description = "Issue retrieved successfully"),
            @ApiResponse(responseCode = "401", description = "Unauthorized"),
            @ApiResponse(responseCode = "404", description = "Issue not found"),
            @ApiResponse(responseCode = "500", description = "Internal server error")
    })
    @GetMapping("/{issueId}")
    ResponseEntity<IssueResponseDto> getIssueById(
            @RequestHeader("Authorization") String accessToken,
            @PathVariable("issueId") UUID issueId);

    // ================= UPDATE =================

    @Operation(summary = "Update an existing issue", description = "Updates the details of an existing issue identified by its ID.", requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "Updated issue details", required = true, content = @Content(schema = @Schema(implementation = IssueCreateRequestDto.class))), responses = {
            @ApiResponse(responseCode = "200", description = "Issue updated successfully"),
            @ApiResponse(responseCode = "400", description = "Invalid issue data or ID provided"),
            @ApiResponse(responseCode = "401", description = "Unauthorized"),
            @ApiResponse(responseCode = "404", description = "Issue not found"),
            @ApiResponse(responseCode = "500", description = "Internal server error")
    })
    @PutMapping("/{issueId}")
    ResponseEntity<IssueResponseDto> updateIssue(
            @RequestHeader("Authorization") String accessToken,
            @PathVariable("issueId") UUID issueId,
            @RequestBody IssueCreateRequestDto issueCreateRequestDto);

}