package ru.ulstu.odin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import ru.ulstu.core.model.response.Response;
import ru.ulstu.odin.model.OdinDto;
import ru.ulstu.odin.model.OdinMetadata;
import ru.ulstu.odin.service.OdinService;

public abstract class OdinController<L, E extends OdinDto> {
    public static final String META_LIST_URL = "/meta/list";
    public static final String META_ELEMENT_URL = "/meta/element";

    private Class<L> listDtoClass;
    private Class<E> elementDtoClass;
    @Autowired
    private OdinService<L, E> odinService;

    public OdinController(Class<L> listDtoClass) {
        this(listDtoClass, null);
    }

    public OdinController(Class<L> listDtoClass, Class<E> elementDtoClass) {
        this.listDtoClass = listDtoClass;
        this.elementDtoClass = elementDtoClass;
    }

    @GetMapping(META_LIST_URL)
    public Response<OdinMetadata> getListModel() {
        return new Response<>(odinService.getListModel(listDtoClass));
    }

    @GetMapping(META_ELEMENT_URL)
    public Response<OdinMetadata> getElementModel() {
        return new Response<>(odinService.getElementModel(elementDtoClass));
    }
}