package org.jenkinsci.plugins.p4.changes;

import com.perforce.p4java.core.file.FileAction;
import com.perforce.p4java.core.file.IFileSpec;
import hudson.scm.ChangeLogSet.AffectedFile;
import hudson.scm.EditType;

public class P4AffectedFile implements AffectedFile {

	private final String path;
	private final String revision;
	private final EditType action;

	public P4AffectedFile(IFileSpec item) {
		this.path = item.getDepotPathString();
		this.revision = "#" + item.getEndRevision();
		this.action = parseFileAction(item.getAction());
	}

	public P4AffectedFile(String path, String revision, FileAction action) {
		this.path = path;
		this.revision = revision;
		this.action = parseFileAction(action);
	}

	@Override
	public String getPath() {
		return path;
	}

	@Override
	public EditType getEditType() {
		return action;
	}

	public String getRevision() {
		return revision;
	}

	public String getAction() {
		return action.getName().toUpperCase();
	}

	private EditType parseFileAction(FileAction fileAction) {
		switch (fileAction) {
		case ADD:
		case MOVE_ADD:
			return EditType.ADD;

		case EDIT:
			return EditType.EDIT;

		case DELETE:
		case MOVE_DELETE:
			return EditType.DELETE;

		default:
			return EditType.EDIT;
		}
	}
}

@@ -1051,107 +1051,875 @@
 se A
-DD:%0A%09%09case MOVE_ADD:%0A%09%09%09return EditType.ADD;%0A%0A%09%09case EDIT:%0A%09%09%09return EditType.EDIT;%0A%0A%09%09case DELETE:
+BANDONED:%0A%09%09%09return new EditType(%22abandoned%22,%22The file was abandoned%22);%0A%09%09case ADD:%0A%09%09case ADDED:%0A%09%09%09return EditType.ADD;%0A%09%09case BRANCH:%0A%09%09%09return new EditType(%22branch%22, %22The file was branched%22);%0A%09%09case COPY_FROM:%0A%09%09%09return new EditType(%22copy_from%22, %22The file was copied%22);%0A%09%09case DELETE:%0A%09%09case DELETED:%0A%09%09%09return EditType.DELETE;%0A%09%09case EDIT:%0A%09%09case EDIT_FROM:%0A%09%09case EDIT_IGNORED:%0A%09%09%09return EditType.EDIT;%0A%09%09case IGNORED:%0A%09%09%09return new EditType(%22ignored%22, %22The file was ignored%22);%0A%09%09case IMPORT:%0A%09%09%09return new EditType(%22import%22, %22The file was imported%22);%0A%09%09case INTEGRATE:%0A%09%09%09return new EditType(%22integrate%22, %22The file was integrated%22);%0A%09%09case MERGE_FROM:%0A%09%09%09return new EditType(%22merge_from%22, %22The file was merged%22);%0A%09%09case MOVE:%0A%09%09%09return new EditType(%22move%22, %22The file was moved%22);%0A%09%09case MOVE_ADD:%0A%09%09%09return new EditType(%22move_add%22, %22File was moved and added%22);
 %0A%09%09c
@@ -1941,32 +1941,36 @@
 :%0A%09%09%09return 
+new 
 EditType
 .DELETE;%0A%0A%09%09
@@ -1957,25 +1957,659 @@
 EditType
-.DELETE;%0A
+(%22move_delete%22, %22File was moved and deleted%22);%0A%09%09case PURGE:%0A%09%09%09return new EditType(%22purge%22, %22The file was purged%22);%0A%09%09case REFRESHED:%0A%09%09%09return new EditType(%22refreshed%22, %22The file was refreshed%22);%0A%09%09case REPLACED:%0A%09%09%09return new EditType(%22replaced%22, %22The file was replaced%22);%0A%09%09case RESOLVED:%0A%09%09%09return new EditType(%22resolved%22, %22The file was resolved%22);%0A%09%09case SYNC:%0A%09%09%09return new EditType(%22sync%22, %22The file was synched%22);%0A%09%09case UNKNOWN:%0A%09%09%09return new EditType(%22unknown%22, %22Unknown%22);%0A%09%09case UNRESOLVED:%0A%09%09%09return new EditType(%22unresolved%22, %22The file was unresolved%22);%0A%09%09case UPDATED:%0A%09%09%09return new EditType(%22updated%22, %22The file was updated%22);
 %0A%09%09defau

Add all FileAction enum types to P4AffectedFile