package com.bcxin.services.commands.results;
import cn.myapps.common.controller.Resource;
import com.bcxin.dtos.ExecuteActionResultDto;
import com.bcxin.enums.ActionStep;
import com.bcxin.saas.core.commands.CommandResultAbstract;
import lombok.Getter;

@Getter
public class CreatedDocumentCommandResult extends CommandResultAbstract {
    private final Resource result;
    private final ActionStep executedStep;

    protected CreatedDocumentCommandResult(boolean success, Resource result, ActionStep executedStep) {
        super(success);
        this.result = result;
        this.executedStep = executedStep;
    }

    public static CreatedDocumentCommandResult success(Resource result, ActionStep executedStep) {
        return new CreatedDocumentCommandResult(true, result, executedStep);
    }

    public static CreatedDocumentCommandResult error(Resource result, ActionStep executedStep) {
        return new CreatedDocumentCommandResult(false, result, executedStep);
    }

    public static CreatedDocumentCommandResult message(Resource result, ActionStep executedStep) {
        return new CreatedDocumentCommandResult(false, result, executedStep);
    }

    public static CreatedDocumentCommandResult result(ExecuteActionResultDto actionResult, ActionStep executedStep) {
        if (actionResult == null) {
            return CreatedDocumentCommandResult.error(null, executedStep);
        }

        switch (actionResult.getResultType()) {
            case OK:
                return CreatedDocumentCommandResult.success(actionResult.getData(), executedStep);
            default:
                return CreatedDocumentCommandResult.error(actionResult.getData(), executedStep);
        }
    }
}
