package cokr.xit.ens.modules.common.ctgy.mblpage.presentation;

import cokr.xit.ens.core.aop.EnsResponseVO;
import cokr.xit.ens.core.exception.code.EnsErrCd;
import cokr.xit.ens.modules.common.ctgy.mblpage.domain.SendDetailMblPage;
import cokr.xit.ens.modules.common.ctgy.mblpage.model.SendDetailMblPageDTO;
import cokr.xit.ens.modules.common.ctgy.mblpage.service.SendDetailMblPageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "SendDetailMblPageApiController")
@Slf4j
@RequiredArgsConstructor
@RestController
public class SendDetailMblPageApiController {

    private final SendDetailMblPageService sendDetailMblPageTestService;


    @Operation(summary = "테스트 모바일페이지 생성")
    @PostMapping(value = "/cmft/mbl/page")
    public ResponseEntity<Map<String, Object>> mblPageCreate(@RequestBody SendDetailMblPageDTO dto) {

        EnsResponseVO<SendDetailMblPage> responseVO = sendDetailMblPageTestService.create(dto);

        Map<String, Object> resultInfo = new HashMap<>();
        resultInfo.put("errCode", responseVO.getErrCode());
        resultInfo.put("errMsg", responseVO.getErrMsg());
        if (EnsErrCd.OK.equals(responseVO.getErrCode())) {
            resultInfo.put("guide", String.format("[:도메인 or :IP]/cmft/mbl/page/%s/%d 를 호출하면 페이지를 확인 할 수 있습니다.", responseVO.getResultInfo().getPostSe(), responseVO.getResultInfo().getSendDetailId()));
            resultInfo.put("uri", String.format("/cmft/mbl/page/%s/%d", responseVO.getResultInfo().getPostSe(), responseVO.getResultInfo().getSendDetailId()));
        } else {
            resultInfo.put("errDetails", responseVO.getResultInfo());
        }

        return new ResponseEntity<Map<String, Object>>(resultInfo, HttpStatus.OK);
    }


}
