package com.its.api.its.controller.database;

import com.its.api.its.model.dto.road.TbRoadDto;
import com.its.api.its.model.dto.road.TbRoadIfscRltnDto;
import com.its.api.its.service.road.TbRoadIfscRltnService;
import com.its.api.its.service.road.TbRoadService;
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 java.util.List;

@Api(tags = "09.기초데이터관리-04.도로")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/database/road")
public class TbRoadController {

    private final TbRoadService service;
    private final TbRoadIfscRltnService ifscRltnService;

    @ApiOperation(value = "도로 전체조회(TB_ROAD)", response = TbRoadDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "", produces = {"application/json; charset=utf8"})
    public List<TbRoadDto> findAll() {
        return service.findAll();
    }

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

    @ApiOperation(value = "도로 전체조회-지역센터(TB_ROAD)", response = TbRoadDto.class, responseContainer = "ArrayList")
    @GetMapping(value = "/local", produces = {"application/json; charset=utf8"})
    public List<TbRoadDto> findLocalAll() {
        return service.findLocalAll();
    }

    @ApiOperation(value = "도로 개별조회(TB_ROAD)", response = TbRoadDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbRoadDto findById(@PathVariable final Long id) {
        return this.service.findById(id);
    }

    /*@ApiOperation(value = "도로 정보변경(TB_ROAD)", response = TbRoadDto.class)
    @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbRoadDto updateById(@PathVariable final Long id, @RequestBody @Valid final TbRoadDto.TbRoadUpdReq req) {
        return this.service.updateById(id, req);
    }*/

    @ApiOperation(value = "도로 명칭변경(TB_ROAD)", response = TbRoadDto.class)
    @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbRoadDto updateNameById(@PathVariable final Long id, @RequestBody final TbRoadDto.TbRoadNameUpdReq req) {
        return this.service.updateNameById(id, req);
    }

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

    @ApiOperation(value = "도로 정보제공구간구성정보변경/생성-개별(TB_ROAD_IFSC_RLTN)", response = TbRoadIfscRltnDto.class)
    @PutMapping(value = "/rltn/{id}", produces = {"application/json; charset=utf8"})
    public List<TbRoadIfscRltnDto> updateIfscRltn(
            @ApiParam(name = "id", value = "도로 ID", example = "3200000006", required = true)
            @PathVariable final Long id,
            @RequestBody final List<TbRoadIfscRltnDto.TbRoadIfscRltnUpdReq> req) {
        return this.ifscRltnService.updateIfscRltn(id, req);
    }

}
