/* This file was generated by SableCC's ObjectMacro. */

package org.sablecc.objectmacro.errormessage;

import java.util.*;

public class MInvalidArgument
        extends Macro {

    private DSeparator ArgumentTextSeparator;

    private DBeforeFirst ArgumentTextBeforeFirst;

    private DAfterLast ArgumentTextAfterLast;

    private DNone ArgumentTextNone;

    final List<String> list_ArgumentText;

    final Context ArgumentTextContext = new Context();

    final StringValue ArgumentTextValue;

    MInvalidArgument(
            Macros macros) {

        setMacros(macros);
        this.list_ArgumentText = new LinkedList<>();

        this.ArgumentTextValue = new StringValue(this.list_ArgumentText,
                this.ArgumentTextContext);
    }

    public void addAllArgumentText(
            List<String> strings) {

        if (this.macros == null) {
            throw ObjectMacroException.parameterNull("ArgumentText");
        }
        if (this.cacheBuilder != null) {
            throw ObjectMacroException
                    .cannotModify(this.getClass().getSimpleName());
        }
        for (String string : strings) {
            if (string == null) {
                throw ObjectMacroException.parameterNull("ArgumentText");
            }

            this.list_ArgumentText.add(string);
        }
    }

    public void addArgumentText(
            String string) {

        if (string == null) {
            throw ObjectMacroException.parameterNull("ArgumentText");
        }
        if (this.cacheBuilder != null) {
            throw ObjectMacroException
                    .cannotModify(this.getClass().getSimpleName());
        }

        this.list_ArgumentText.add(string);
    }

    private String buildArgumentText() {

        StringBuilder sb = new StringBuilder();
        List<String> strings = this.list_ArgumentText;

        int i = 0;
        int nb_strings = strings.size();

        if (this.ArgumentTextNone != null) {
            sb.append(this.ArgumentTextNone.apply(i, "", nb_strings));
        }

        for (String string : strings) {

            if (this.ArgumentTextBeforeFirst != null) {
                string = this.ArgumentTextBeforeFirst.apply(i, string,
                        nb_strings);
            }

            if (this.ArgumentTextAfterLast != null) {
                string = this.ArgumentTextAfterLast.apply(i, string,
                        nb_strings);
            }

            if (this.ArgumentTextSeparator != null) {
                string = this.ArgumentTextSeparator.apply(i, string,
                        nb_strings);
            }

            sb.append(string);
            i++;
        }

        return sb.toString();
    }

    StringValue getArgumentText() {

        return this.ArgumentTextValue;
    }

    private void initArgumentTextDirectives() {

    }

    @Override
    void apply(
            InternalsInitializer internalsInitializer) {

        internalsInitializer.setInvalidArgument(this);
    }

    public String build() {

        CacheBuilder cache_builder = this.cacheBuilder;

        if (cache_builder == null) {
            cache_builder = new CacheBuilder();
        }
        else if (cache_builder.getExpansion() == null) {
            throw new InternalException("Cycle detection detected lately");
        }
        else {
            return cache_builder.getExpansion();
        }
        this.cacheBuilder = cache_builder;
        List<String> indentations = new LinkedList<>();

        initArgumentTextDirectives();

        StringBuilder sb0 = new StringBuilder();

        MCommandLineErrorHead m1 = getMacros().newCommandLineErrorHead();

        sb0.append(m1.build(null));
        sb0.append(LINE_SEPARATOR);
        sb0.append(LINE_SEPARATOR);
        sb0.append("The following argument is rejected:");
        sb0.append(LINE_SEPARATOR);
        sb0.append(" ");
        sb0.append(buildArgumentText());
        sb0.append(LINE_SEPARATOR);
        sb0.append("It is invalid.");
        sb0.append(LINE_SEPARATOR);
        sb0.append(LINE_SEPARATOR);
        MCommandLineErrorTail m2 = getMacros().newCommandLineErrorTail();

        sb0.append(m2.build(null));

        cache_builder.setExpansion(sb0.toString());
        return sb0.toString();
    }

    @Override
    String build(
            Context context) {

        return build();
    }

    private void setMacros(
            Macros macros) {

        if (macros == null) {
            throw new InternalException("macros cannot be null");
        }

        this.macros = macros;
    }
}
