001/*
002 * Copyright 2025 devteam@scivicslab.com
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing,
011 * software distributed under the License is distributed on an
012 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied.  See the License for the
014 * specific language governing permissions and limitations
015 * under the License.
016 */
017
018package com.scivicslab.actoriac.report.sections.basic;
019
020import com.scivicslab.actoriac.report.SectionBuilder;
021
022/**
023 * POJO section builder that outputs the workflow name.
024 *
025 * <p>Pure business logic - no {@code CallableByActionName}.
026 * Use {@link WorkflowNameSectionIIAR} to expose as an actor.</p>
027 *
028 * <h2>Output example:</h2>
029 * <pre>
030 * [Workflow Name]
031 * main-cluster-status
032 * </pre>
033 *
034 * @author devteam@scivicslab.com
035 * @since 2.16.0
036 */
037public class WorkflowNameSection implements SectionBuilder {
038
039    private String workflowName;
040    private String workflowPath;
041
042    /**
043     * Sets the workflow name.
044     *
045     * @param name the workflow name from YAML
046     */
047    public void setWorkflowName(String name) {
048        this.workflowName = name;
049    }
050
051    /**
052     * Sets the workflow file path (used as fallback if name is not set).
053     *
054     * @param path the workflow file path
055     */
056    public void setWorkflowPath(String path) {
057        this.workflowPath = path;
058    }
059
060    @Override
061    public String generate() {
062        String name = workflowName;
063        if (name == null || name.isEmpty()) {
064            // Fall back to file name
065            if (workflowPath != null && !workflowPath.isEmpty()) {
066                int lastSlash = workflowPath.lastIndexOf('/');
067                name = lastSlash >= 0 ? workflowPath.substring(lastSlash + 1) : workflowPath;
068            } else {
069                name = "(unknown)";
070            }
071        }
072        return "[Workflow Name]\n" + name + "\n";
073    }
074
075    @Override
076    public String getTitle() {
077        return null;  // Title is embedded in content
078    }
079}