package com.kospo.talk.controller;

import com.kospo.talk.config.exception.CustomErrorResponse;
import com.kospo.talk.model.SmUserId;
import com.kospo.talk.payload.SmUserDto;
import com.kospo.talk.payload.WorkDto;
import com.kospo.talk.service.SmUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.Date;

@RestController
@Tag(name = "SmUser Api", description = "유지보수 관리")
@RequestMapping("/api")
@RequiredArgsConstructor
public class SmUserController {
    private final SmUserService smUserService;

    @Operation(summary = "유지보수 요원 조회", description = "업무 아이디로 유지보수 요원 조회")
    @ApiResponses({
            @ApiResponse(description = "Success", responseCode = "200",
                    content = @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", array = @ArraySchema(
                            schema = @Schema(oneOf =
                                    {SmUserDto.class})
                    ))),
            @ApiResponse(description = "Not found", responseCode = "404",
                    content = @io.swagger.v3.oas.annotations.media.Content(mediaType = "text/plain", schema = @Schema(oneOf =
                            {String.class}))),
            @ApiResponse(description = "Internal Error", responseCode = "500",
                    content = @io.swagger.v3.oas.annotations.media.Content(mediaType = "application/json", schema = @Schema(oneOf =
                            {CustomErrorResponse.class })))
    })
    @GetMapping("/smUser")
    @Transactional(readOnly = true)
    public ResponseEntity findByWorkId(
            @Parameter(description = "업무코드") @RequestParam(value="workId", defaultValue = "") String workId,
            Principal principal
    ) {
        return ResponseEntity.ok(smUserService.findByWorkId(workId));
    }

}
