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.OK;

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) {
                    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()));
                    }
                }
            } else {
                out.println(glossary.getName());
            }
        }
    }
}

@@ -460,18 +460,154 @@
 nStatus.
-OK
+ERROR;%0Aimport static com.crowdin.cli.utils.console.ExecutionStatus.OK;%0Aimport static com.crowdin.cli.utils.console.ExecutionStatus.WARNING
 ;%0A%0Aclass
@@ -1347,36 +1347,126 @@
    if (isVerbose
-) %7B%0A
+ && (glossary.getTerms() == null %7C%7C glossary.getTerms() %3E 0)) %7B%0A                    try %7B%0A    
                 
@@ -1540,24 +1540,28 @@
             
+  
+  
 for (Term te
@@ -1570,24 +1570,28 @@
  : terms) %7B%0A
+    
             
@@ -1629,16 +1629,20 @@
 format(%0A
+    
         
@@ -1769,24 +1769,165 @@
 iption()));%0A
+                        %7D%0A                    %7D catch (Exception e) %7B%0A                        out.println(WARNING.withIcon(e.getMessage()));%0A
             

Fix 'glossary list --verbose' for non-managers