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

import com.its.op.dto.its.atrd.TbAtrdDto;
import com.its.op.dto.its.common.UsageCountDto;
import com.its.op.service.its.atrd.TbAtrdService;
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.기초데이터관리-05.간선도로관리")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/database/atrd")
public class TbAtrdController {

    private final TbAtrdService service;

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

    @ApiOperation(value = "간선도로 개별조회(TB_ATRD)", response = TbAtrdDto.class)
    @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbAtrdDto findById(
            @ApiParam(name = "id", value = "간선도로 ID", example = "ATR2001", required = true)
            @PathVariable final String id) {
        return this.service.findById(id);
    }

    @ApiOperation(value = "간선도로 사용여부 조회(신규 아이디 만들때 사용)", response = UsageCountDto.class)
    @GetMapping(value = "/usage/{id}", produces = {"application/json; charset=utf8"})
    public UsageCountDto findUsageId(
            @ApiParam(name = "id", value = "간선도로 ID", example = "ATR2001", required = true)
            @PathVariable final String id) {
        return this.service.findUsageId(id);
    }

    @ApiOperation(value = "간선도로 정보변경/생성-개별(TB_ATRD)", response = TbAtrdDto.class)
    @PostMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbAtrdDto mergeInfo(@PathVariable("id") String id, @RequestBody @Valid final TbAtrdDto.TbAtrdUpdReq req) {
        return this.service.mergeInfo(id, req);
    }

    @ApiOperation(value = "간선도로 정보삭제-개별(TB_ATRD)", response = TbAtrdDto.class)
    @DeleteMapping(value = "/{id}", produces = {"application/json; charset=utf8"})
    public TbAtrdDto deleteDataById(@PathVariable("id") String id) {
        return this.service.deleteById(id);
    }

}
