package ru.matevosyan.models;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * This class was created for items, that's determine specific and hole description and hold it together as item.
 * Created on 15.11.2016.
 * @since 1.0
 * @author Matevosyan Vardan
 * @version 1.0
 *
 */

public class Item {

    /**
     * Instance variable id which is the Items identifier.
     */

    private String id;

    /**
     * Instance variable name which is the Items name.
     */

    private String name;

    /**
     * Instance variable description which is the Items description.
     */

    private String description;

    /**
     * Instance variable create Items create date.
     */

    private Date create;

    /**
     * Variable commentPosition is position in Comments array which in addComments method is increment own value which is start from the 0.
     */

    private int commentPosition = 0;

    /**
     * Variable COMMENTS_CAP is comments array capacity.
     */

    private static final int COMMENTS_CAP = 5;

    /**
     * Instance variable comments is array of comments that hold all comments and store it in Item.
     */

//    private Comments[] comments = new Comments[COMMENTS_CAP];

    private ArrayList<Comments> comments = new ArrayList<>();
    /**
     * Created for override the default constructor.
     */

    public Item() {
    }

    /**
     * Created for override the parameters we have the constructor.
     * @param name which is the Items name
     * @param description which is the Items description
     */

    public Item(String name, String description) {
        this.name = name;
        this.description = description;
        this.create = getCreateDate();
    }

    /**
     * Create getter for field name.
     * @return  <code>name</code>
     */

    public String getName() {

        return this.name;
    }

    /**
     * Create getter for field description.
     * @return  <code>description</code>
     */

    public String getDescription() {
        return this.description;
    }

    /**
     * Create getter for field create.
     * @return  <code>create</code>
     */

    public String getCreate() {
        SimpleDateFormat sFormat = new SimpleDateFormat("dd.MM.yyyy");
        return sFormat.format(getCreateDate());
    }

    /**
     * Create setter for field id.
     * @param id  value for set the Items id
     */

    public void setId(String id) {
        this.id = id;
    }

    /**
     * Create getter for field create.
     * @return  <code>id</code>
     */

    public String getId() {
        return this.id;
    }

    /**
     * addComments method created for adding comments to Items, we can find the items which of them we want to add and added.
     * @param comment it is the String type, we type the comment add send it to addComment method
     * @return  <code>comments</code>
     */

//    public Comments[] addComment(String comment) {
//        comments[commentPosition] = (new Comments(comment));
//        commentPosition++;
//        return comments;
    public ArrayList<Comments> addComment(String comment) {
        this.comments.add(new Comments(comment));
        return this.comments;
    }

    /**
     * Create getter for field comments in array of comments.
     * @return  <code>comments</code>
     */

//    public Comments[] getComments() {
//        return comments;
//    }

    public ArrayList<Comments> getComments() {
        return comments;
    }


    /**
     * Create getter for field create for create the date in millisecond.
     * @return currentTime
     */

    private Date getCreateDate() {
        long create = System.currentTimeMillis();
        return new Date(create);
    }

    /**
     * Override toString method for print out formatting items.
     * @return the formatting line
     */

       @Override
    public String toString() {

       return String.format("Id: %s; Name: %s; Description: %s; Date: %s; Comments: %s", this.id, this.name, this.description, this.create, this.comments);

    }

    /**
     * getAllComment get us all item comments.
     * It is using for handsome printing comments to user.
     * @return <code>allComments</code>
     */
//
//    public ArrayList<Comments> getAllComment() {
//        Comments[] allComments = new Comments[COMMENTS_CAP];
//        for (int index = 0; index != COMMENTS_CAP; index++) {
//            allComments[index] = this.comments[index];
//        }
//        return allComments;
//    }

    public ArrayList<Comments> getAllComment() {
        ArrayList<Comments> allComments = new ArrayList<>();
        for (int index = 0; index != COMMENTS_CAP; index++) {
            allComments.add(this.comments.get(index));
        }
        return allComments;
    }
}

@@ -758,325 +758,8 @@
 e;%0A%0A
-    /**%0A     * Variable commentPosition is position in Comments array which in addComments method is increment own value which is start from the 0.%0A     */%0A%0A    private int commentPosition = 0;%0A%0A    /**%0A     * Variable COMMENTS_CAP is comments array capacity.%0A     */%0A%0A    private static final int COMMENTS_CAP = 5;%0A%0A
     
@@ -875,73 +875,8 @@
 */%0A%0A
-//    private Comments%5B%5D comments = new Comments%5BCOMMENTS_CAP%5D;%0A%0A
     
@@ -2550,180 +2550,8 @@
 */%0A%0A
-//    public Comments%5B%5D addComment(String comment) %7B%0A//        comments%5BcommentPosition%5D = (new Comments(comment));%0A//        commentPosition++;%0A//        return comments;%0A
     
@@ -2814,84 +2814,8 @@
 */%0A%0A
-//    public Comments%5B%5D getComments() %7B%0A//        return comments;%0A//    %7D%0A%0A
     
@@ -3406,16 +3406,31 @@
 is.name,
+%0A              
  this.de
@@ -3642,296 +3642,8 @@
   */
-%0A//%0A//    public ArrayList%3CComments%3E getAllComment() %7B%0A//        Comments%5B%5D allComments = new Comments%5BCOMMENTS_CAP%5D;%0A//        for (int index = 0; index != COMMENTS_CAP; index++) %7B%0A//            allComments%5Bindex%5D = this.comments%5Bindex%5D;%0A//        %7D%0A//        return allComments;%0A//    %7D
 %0A%0A  
@@ -3754,74 +3754,8 @@
 ();%0A
-        for (int index = 0; index != COMMENTS_CAP; index++) %7B%0A    
     
@@ -3773,16 +3773,19 @@
 ents.add
+All
 (this.co
@@ -3794,31 +3794,10 @@
 ents
-.get(index));%0A        %7D
+);
 %0A   

change all array to arrayList