package com.crowdin.cli.commands.actions;

import com.crowdin.cli.client.ClientGlossary;
import com.crowdin.cli.commands.NewAction;
import com.crowdin.cli.commands.Outputter;
import com.crowdin.cli.properties.BaseProperties;
import com.crowdin.client.glossaries.model.Glossary;
import com.crowdin.client.glossaries.model.Term;

import java.util.List;

import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE;
import static com.crowdin.cli.utils.console.ExecutionStatus.ERROR;
import static com.crowdin.cli.utils.console.ExecutionStatus.OK;
import static com.crowdin.cli.utils.console.ExecutionStatus.WARNING;

class GlossaryListAction implements NewAction<BaseProperties, ClientGlossary> {

    private final boolean isVerbose;
    private final boolean plainView;

    public GlossaryListAction(boolean plainView, boolean isVerbose) {
        this.plainView = plainView;
        this.isVerbose = isVerbose;
    }

    @Override
    public void act(Outputter out, BaseProperties pb, ClientGlossary client) {
        List<Glossary> glossaries = client.listGlossaries();
        for (Glossary glossary : glossaries) {
            if (!plainView) {
                out.println(OK.withIcon(
                    String.format(RESOURCE_BUNDLE.getString("message.glossary.list"), glossary.getName(), glossary.getId(), glossary.getTerms())));
                if (isVerbose && (glossary.getTerms() == null || glossary.getTerms() > 0)) {
                    try {
                        List<Term> terms = client.listTerms(glossary.getId());
                        for (Term term : terms) {
                            out.println(String.format(
                                RESOURCE_BUNDLE.getString("message.glossary.list_term"), term.getId(), term.getText(), term.getDescription()));
                        }
                    } catch (Exception e) {
                        out.println(WARNING.withIcon(RESOURCE_BUNDLE.getString("error.glossary.no_permission")));
                    }
                }
            } else {
                out.println(glossary.getName());
            }
        }
    }
}

@@ -1363,63 +1363,29 @@
  && 
-(glossary.getTerms() == null %7C%7C glossary.getTerms() %3E 0
+mayHaveTerms(glossary
 )) %7B
@@ -1536,24 +1536,135 @@
  : terms) %7B%0A
+                            String description = (term.getDescription() != null) ? term.getDescription() : %22%22;%0A
             
@@ -1825,25 +1825,17 @@
 Text(), 
-term.getD
+d
 escripti
@@ -1836,18 +1836,16 @@
 cription
-()
 ));%0A    
@@ -2163,11 +2163,165 @@
  %7D%0A    %7D
+%0A%0A    private boolean mayHaveTerms(Glossary glossary) %7B%0A        return glossary != null && (glossary.getTerms() == null %7C%7C glossary.getTerms() %3E 0);%0A    %7D
 %0A%7D%0A

Fix verbose message for 'glossary list'