package cokr.xit.ens.modules.common.ctgy.sys.mng.presentation;

import cokr.xit.ens.core.aop.EnsResponseVO;
import cokr.xit.ens.modules.common.ctgy.sys.mng.domain.OrgMng;
import cokr.xit.ens.modules.common.ctgy.sys.mng.model.OrgMngDTO;
import cokr.xit.ens.modules.common.ctgy.sys.mng.model.OrgMngSearchDTO;
import cokr.xit.ens.modules.common.ctgy.sys.mng.service.OrgMngService;
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.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

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

    private final OrgMngService orgMngService;




    @Operation(summary = "기관 목록 조회")
    @GetMapping(value = "/sys/mng/org", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO<List<OrgMng>>> findAll(OrgMngSearchDTO searchDTO){
        EnsResponseVO<List<OrgMng>> responseVO = orgMngService.findAllBySearchDTO(searchDTO);

        return new ResponseEntity<EnsResponseVO<List<OrgMng>>>(responseVO, HttpStatus.OK);
    }




    @Operation(summary = "기관정보 조회")
    @GetMapping(value = "/sys/mng/org/{orgCd}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> find(@PathVariable String orgCd){
        EnsResponseVO responseVO = orgMngService.find(orgCd);

        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }




    @Operation(summary = "기관정보 신규 등록")
    @PostMapping(value = "/sys/mng/org", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> add(@RequestBody OrgMngDTO reqDTO){
        EnsResponseVO responseVO = orgMngService.add(reqDTO);

        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }




    @Operation(summary = "기관정보 수정")
    @PutMapping(value = "/sys/mng/org", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> modify(@RequestBody OrgMngDTO reqDTO){
        EnsResponseVO responseVO = orgMngService.modify(reqDTO);

        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }




    @Operation(summary = "기관정보 삭제")
    @DeleteMapping(value = "/sys/mng/org/{orgCd}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<EnsResponseVO> delete(@PathVariable String orgCd){
        EnsResponseVO responseVO = orgMngService.delete(orgCd);

        return new ResponseEntity<EnsResponseVO>(responseVO, HttpStatus.OK);
    }

}
