package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.EditCommand.EditPersonDescriptor;
import seedu.address.logic.commands.IncorrectCommand;
import seedu.address.model.tag.UniqueTagList;

/**
 * Parses input arguments and creates a new EditCommand object
 */
public class EditCommandParser {

    /**
     * Parses the given {@code String} of arguments in the context of the EditCommand
     * and returns an EditCommand object for execution.
     */
    public Command parse(String args) {
        assert args != null;
        ArgumentTokenizer argsTokenizer =
                new ArgumentTokenizer(PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG);
        argsTokenizer.tokenize(args);
        List<Optional<String>> preambleFields = ParserUtil.splitPreamble(argsTokenizer.getPreamble().orElse(""), 2);

        Optional<Integer> index = preambleFields.get(0).flatMap(ParserUtil::parseIndex);
        if (!index.isPresent()) {
            return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
        }

        EditPersonDescriptor editPersonDescriptor = new EditPersonDescriptor();
        try {
            editPersonDescriptor.setName(ParserUtil.parseName(preambleFields.get(1)));
            editPersonDescriptor.setPhone(ParserUtil.parsePhone(argsTokenizer.getValue(PREFIX_PHONE)));
            editPersonDescriptor.setEmail(ParserUtil.parseEmail(argsTokenizer.getValue(PREFIX_EMAIL)));
            editPersonDescriptor.setAddress(ParserUtil.parseAddress(argsTokenizer.getValue(PREFIX_ADDRESS)));
            editPersonDescriptor.setTags(parseTagsForEdit(ParserUtil.toSet(argsTokenizer.getAllValues(PREFIX_TAG))));
        } catch (IllegalValueException ive) {
            return new IncorrectCommand(ive.getMessage());
        }

        if (!editPersonDescriptor.isAnyFieldEdited()) {
            return new IncorrectCommand(EditCommand.MESSAGE_NOT_EDITED);
        }

        return new EditCommand(index.get(), editPersonDescriptor);
    }

    /**
     * Parses {@code Collection<String> tags} into an {@code Optional<UniqueTagList>} if {@code tags} is non-empty.
     * If {@code tags} contain only one element which is an empty string, it will be parsed into a
     * {@code Optional<UniqueTagList>} containing zero tags.
     */
    private Optional<UniqueTagList> parseTagsForEdit(Collection<String> tags) throws IllegalValueException {
        assert tags != null;

        if (tags.isEmpty()) {
            return Optional.empty();
        }
        Collection<String> tagSet = tags.size() == 1 && tags.contains("") ? Collections.emptySet() : tags;
        return Optional.of(ParserUtil.parseTags(tagSet));
    }

}

@@ -170,23 +170,19 @@
 .PREFIX_
-ADDRESS
+TAG
 ;%0Aimport
@@ -233,21 +233,18 @@
 .PREFIX_
-EMAIL
+ID
 ;%0Aimport
@@ -295,19 +295,22 @@
 .PREFIX_
-PHO
+DEADLI
 NE;%0Aimpo
@@ -363,19 +363,27 @@
 .PREFIX_
-TAG
+DESCRIPTION
 ;%0A%0Aimpor
@@ -692,30 +692,28 @@
 Command.Edit
-Person
+Task
 Descriptor;%0A
@@ -1232,19 +1232,22 @@
 (PREFIX_
-PHO
+DEADLI
 NE, PREF
@@ -1249,21 +1249,27 @@
  PREFIX_
-EMAIL
+DESCRIPTION
 , PREFIX
@@ -1269,23 +1269,18 @@
  PREFIX_
-ADDRESS
+ID
 , PREFIX
@@ -1699,30 +1699,28 @@
         Edit
-Person
+Task
 Descriptor e
@@ -1718,30 +1718,28 @@
 criptor edit
-Person
+Task
 Descriptor =
@@ -1747,22 +1747,20 @@
 new Edit
-Person
+Task
 Descript
@@ -1787,38 +1787,36 @@
             edit
-Person
+Task
 Descriptor.setNa
@@ -1872,38 +1872,36 @@
             edit
-Person
+Task
 Descriptor.setPh
@@ -1898,19 +1898,22 @@
 ptor.set
-Pho
+Deadli
 ne(Parse
@@ -1927,11 +1927,14 @@
 arse
-Pho
+Deadli
 ne(a
@@ -1966,11 +1966,14 @@
 FIX_
-PHO
+DEADLI
 NE))
@@ -1983,38 +1983,36 @@
             edit
-Person
+Task
 Descriptor.setEm
@@ -2009,21 +2009,27 @@
 ptor.set
-Email
+Description
 (ParserU
@@ -2041,13 +2041,19 @@
 arse
-Email
+Description
 (arg
@@ -2083,13 +2083,19 @@
 FIX_
-EMAIL
+DESCRIPTION
 )));
@@ -2103,38 +2103,36 @@
             edit
-Person
+Task
 Descriptor.setAd
@@ -2129,23 +2129,18 @@
 ptor.set
-Address
+ID
 (ParserU
@@ -2152,15 +2152,10 @@
 arse
-Address
+Id
 (arg
@@ -2185,15 +2185,10 @@
 FIX_
-ADDRESS
+ID
 )));
@@ -2200,30 +2200,28 @@
         edit
-Person
+Task
 Descriptor.s
@@ -2433,30 +2433,28 @@
    if (!edit
-Person
+Task
 Descriptor.i
@@ -2610,14 +2610,12 @@
 edit
-Person
+Task
 Desc

Modify EditCommandParser class