package com.cloudhandson.vpdbackoffice.web;

import com.cloudhandson.vpdbackoffice.domain.operation.OperationHealthSummary;
import com.cloudhandson.vpdbackoffice.service.MaskingRuleService;
import com.cloudhandson.vpdbackoffice.service.OperationStatusService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class OperationStatusController {

  private final OperationStatusService service;
  private final MaskingRuleService maskingRuleService;

  public OperationStatusController(OperationStatusService service, MaskingRuleService maskingRuleService) {
    this.service = service;
    this.maskingRuleService = maskingRuleService;
  }

  @GetMapping("/operation-status")
  public String status(Model model) {
    var rows = service.findRows();
    var maskingPolicyStatuses = maskingRuleService.findPolicyStatuses();
    model.addAttribute("rows", rows);
    model.addAttribute("maskingPolicyStatuses", maskingPolicyStatuses);
    model.addAttribute("summary", OperationHealthSummary.from(rows, maskingPolicyStatuses));
    return "operation-status";
  }
}
