package com.caliverse.admin.domain.api;

import com.caliverse.admin.domain.request.AuthenticateRequest;
import com.caliverse.admin.domain.request.DataRequest;
import com.caliverse.admin.domain.request.LogGenericRequest;
import com.caliverse.admin.domain.response.DataResponse;
import com.caliverse.admin.domain.response.LogResponse;
import com.caliverse.admin.domain.service.DataService;
import com.caliverse.admin.global.common.code.CommonCode;
import com.caliverse.admin.global.common.code.ErrorCode;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Tag(name = "데이터 관련", description = "데이터 관련 api 입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/data")

public class DataController {

    private final DataService dataService;

    @Value("${spring.profiles.active}")
    private String activeProfile;

    @PostMapping("/init-list")
    public ResponseEntity<DataResponse> initHistoryList(
            @RequestBody LogGenericRequest logGenericRequest){
        if(activeProfile.equals("live")){
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(DataResponse.builder()
                    .status(CommonCode.ERROR.getHttpStatus())
                    .result(ErrorCode.NOT_FOUNT_API.toString())
                    .build());
        }

        return ResponseEntity.ok().body( dataService.initHistoryList(logGenericRequest));
    }

    //데이터 초기화
    @PostMapping("/init-data")
    public ResponseEntity<DataResponse> initData(@RequestBody DataRequest dataRequest){
        if(activeProfile.equals("live")){
            return ResponseEntity.status(HttpStatus.NOT_FOUND).body(DataResponse.builder()
                    .status(CommonCode.ERROR.getHttpStatus())
                    .result(ErrorCode.NOT_FOUNT_API.toString())
                    .build());
        }
        return ResponseEntity.ok().body(dataService.initData(dataRequest));
    }
}
