package com.iqser.red.service.persistence.management.v1.processor.migration;

import java.util.List;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import lombok.Data;
import lombok.RequiredArgsConstructor;

@Data
@RestController
@RequiredArgsConstructor
@RequestMapping("/private/migration")
public class MigrationController {

    private final List<Migration> migrations;


    @PostMapping
    public void run(@RequestParam("migrationName") String migrationName, @RequestParam("force") boolean force) {

        migrations.stream().filter(m -> m.getName().equalsIgnoreCase(migrationName) || m.getClass().getSimpleName().equalsIgnoreCase(migrationName)).forEach(m -> m.run(force));
    }

}
