package com.storycove.dto;

import java.util.ArrayList;
import java.util.List;

public class ZIPImportResponse {

    private boolean success;
    private String message;
    private int totalFiles;
    private int successfulImports;
    private int failedImports;
    private List<FileImportResponse> results;
    private List<String> warnings;

    public ZIPImportResponse() {
        this.results = new ArrayList<>();
        this.warnings = new ArrayList<>();
    }

    public static ZIPImportResponse create(List<FileImportResponse> results) {
        ZIPImportResponse response = new ZIPImportResponse();
        response.setResults(results);
        response.setTotalFiles(results.size());
        response.setSuccessfulImports((int) results.stream().filter(FileImportResponse::isSuccess).count());
        response.setFailedImports((int) results.stream().filter(r -> !r.isSuccess()).count());

        if (response.getFailedImports() == 0) {
            response.setSuccess(true);
            response.setMessage("All files imported successfully");
        } else if (response.getSuccessfulImports() == 0) {
            response.setSuccess(false);
            response.setMessage("All file imports failed");
        } else {
            response.setSuccess(true);
            response.setMessage("Partial success: " + response.getSuccessfulImports() + " imported, " + response.getFailedImports() + " failed");
        }

        return response;
    }

    public void addWarning(String warning) {
        this.warnings.add(warning);
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getTotalFiles() {
        return totalFiles;
    }

    public void setTotalFiles(int totalFiles) {
        this.totalFiles = totalFiles;
    }

    public int getSuccessfulImports() {
        return successfulImports;
    }

    public void setSuccessfulImports(int successfulImports) {
        this.successfulImports = successfulImports;
    }

    public int getFailedImports() {
        return failedImports;
    }

    public void setFailedImports(int failedImports) {
        this.failedImports = failedImports;
    }

    public List<FileImportResponse> getResults() {
        return results;
    }

    public void setResults(List<FileImportResponse> results) {
        this.results = results;
    }

    public List<String> getWarnings() {
        return warnings;
    }

    public void setWarnings(List<String> warnings) {
        this.warnings = warnings;
    }
}
