package com.inkasso.factoring.code.controller;

import java.util.List;

import com.inkasso.adapter.response.ResponseData;
import com.inkasso.factoring.code.model.DataSourceDTO;
import com.inkasso.factoring.code.model.PropertyDTO;
import com.inkasso.factoring.code.model.TableDTO;
import com.inkasso.factoring.code.service.EntityGenerateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;


@RestController
@RequestMapping(value = "/entitygenerator")
public class EntityGenerateController {

    @Autowired
    private EntityGenerateService entityGenerateService;

    @RequestMapping(value = "/dataSources", method = {RequestMethod.GET})
    public Mono<ResponseData> getDataSources() {

        List<DataSourceDTO> list = entityGenerateService.getDataSources();
        return Mono.just(ResponseData.success(list));
    }

    @RequestMapping(value = "/tables/{dataSource}", method = {RequestMethod.GET})
    public Mono<ResponseData> getTablesByDataSource(@PathVariable("dataSource") String dataSource) {
        List<TableDTO> list = entityGenerateService.getTablesByDataSource(dataSource);
        return Mono.just(ResponseData.success(list));
    }

    @RequestMapping(value = "/columns/{dataSource}/{tableName}", method = {RequestMethod.GET})
    public Mono<ResponseData> getColumnsByTableAndDataSource(@PathVariable("tableName") String tableName,
                                                             @PathVariable("dataSource") String dataSource) {
        List<PropertyDTO> list = entityGenerateService.getColumnsByTableAndDataSource(tableName, dataSource);
        return Mono.just(ResponseData.success(list));
    }

}
