package de.avatic.taric.controller;

import de.avatic.taric.model.Measure;
import de.avatic.taric.model.MeasureAction;
import de.avatic.taric.model.MeasureSeries;
import de.avatic.taric.repository.MeasureActionRepository;
import de.avatic.taric.repository.MeasureRepository;
import de.avatic.taric.repository.MeasureSeriesRepository;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/measures")
@Tag(name = "Measures", description = "API endpoints for trade measures, measure series, and measure actions")
public class MeasureController {

    private final MeasureRepository measureRepository;
    private final MeasureSeriesRepository measureSeriesRepository;
    private final MeasureActionRepository measureActionRepository;

    public MeasureController(MeasureRepository measureRepository, MeasureSeriesRepository measureSeriesRepository, MeasureActionRepository measureActionRepository) {
        this.measureRepository = measureRepository;
        this.measureSeriesRepository = measureSeriesRepository;
        this.measureActionRepository = measureActionRepository;
    }

    @Operation(
            summary = "Get all measures",
            description = "Retrieves a complete list of all trade measures in the system"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "Successfully retrieved measures",
                    content = @Content(mediaType = "application/json", schema = @Schema(implementation = Measure.class))
            )
    })
    @GetMapping
    public Iterable<Measure> getMeasures() {
        return measureRepository.findAll();
    }

    @Operation(
            summary = "Get all measure series",
            description = "Retrieves a complete list of all measure series that group related measures together"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "Successfully retrieved measure series",
                    content = @Content(mediaType = "application/json", schema = @Schema(implementation = MeasureSeries.class))
            )
    })
    @GetMapping("/series")
    public Iterable<MeasureSeries> getMeasuresSeries() {
        return measureSeriesRepository.findAll();
    }

    @Operation(
            summary = "Get all measure actions",
            description = "Retrieves a complete list of all measure actions that define possible actions on measures"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "Successfully retrieved measure actions",
                    content = @Content(mediaType = "application/json", schema = @Schema(implementation = MeasureAction.class))
            )
    })
    @GetMapping("/action")
    public Iterable<MeasureAction> getMeasuresAction() {
        return measureActionRepository.findAll();
    }
}