package com.its.op.controller.its.database;

import com.its.op.dto.its.ifsc.TbIfscDto;
import com.its.op.dto.its.ifsc.TbIfscLinkRltnDto;
import com.its.op.dto.its.link.TbLinkDto;
import com.its.op.service.its.ifsc.TbIfscLinkRltnService;
import com.its.op.service.its.ifsc.TbIfscService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "09.기초데이터관리-03.정보제공구간")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/database/ifsc")
public class TbIfscController {

    private final TbIfscService service;
    private final TbIfscLinkRltnService linkRltnService;

    @ApiOperation(value = "정보제공구간 전체조회(TB_IFSC)", response = TbIfscDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbIfscDto> findAll() {
        return service.findAll();
    }

    @ApiOperation(value = "정보제공구간 전체조회-삭제되지 않은 정보(TB_IFSC)", response = TbIfscDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/list", produces = {"application/json; charset=utf8"})
    public List<TbIfscDto> findAllList() {
        return service.findAllList();
    }

    @ApiOperation(value = "정보제공구간 전체조회-지역센터(TB_IFSC)", response = TbLinkDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/local", produces = {"application/json; charset=utf8"})
    public List<TbIfscDto> findLocalAll() {
        return service.findLocalAll();
    }

    @ApiOperation(value = "정보제공구간 개별조회(TB_IFSC)", response = TbIfscDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbIfscDto findById(@PathVariable final Long id) {
        return this.service.findById(id);
    }

    /*@ApiOperation(value = "정보제공구간 정보변경(TB_IFSC)", response = TbIfscDto.class)
    @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbIfscDto updateById(@PathVariable final Long id, @RequestBody @Valid final TbIfscDto.TbIfscUpdReq req) {
        return this.service.updateById(id, req);
    }*/

    @ApiOperation(value = "정보제공구간 링크구성정보조회-개별(TB_IFSC_LINK_RLTN)", response = TbIfscLinkRltnDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/rltn/{id}", produces = {"application/json; charset=utf8"})
    public List<TbIfscLinkRltnDto> findLinkRltnById(
            @ApiParam(name = "id", value = "정보제공구간 ID", example = "2200000488", required = true)
            @PathVariable final Long id) {
        return this.linkRltnService.findLinkRltnById(id);
    }

    @ApiOperation(value = "정보제공구간 링크구성정보변경/생성-개별(TB_IFSC_LINK_RLTN)", response = TbIfscLinkRltnDto.class)
    @PutMapping(value = "/rltn/{id}", produces = {"application/json; charset=utf8"})
    public List<TbIfscLinkRltnDto> updateLinkRltn(
            @ApiParam(name = "id", value = "정보제공구간 ID", example = "2200000488", required = true)
            @PathVariable final Long id,
            @RequestBody final List<TbIfscLinkRltnDto.TbIfscLinkRltnUpdReq> req) {
        return this.linkRltnService.updateLinkRltn(id, req);
    }

    @ApiOperation(value = "정보제공구간 명칭변경(TB_IFSC)", response = TbIfscDto.class)
    @PutMapping(value = "/name/{id}", produces = {"application/json; charset=utf8"})
    public TbIfscDto updateNameById(@PathVariable final Long id, @RequestBody final TbIfscDto.TbIfscNameUpdReq req) {
        return this.service.updateNameById(id, req);
    }

    @ApiOperation(value = "정보제공구간 구간등급 변경(TB_IFSC)", response = TbIfscDto.class)
    @PutMapping(value = "/sect-grad/{id}", produces = {"application/json; charset=utf8"})
    public TbIfscDto updateSectGradById(@PathVariable final Long id, @RequestBody @Valid final TbIfscDto.TbIfscSectGradUpdReq req) {
        return this.service.updateSectGradById(id, req);
    }

}
