public class CreateOrDeleteEventStory extends BaseUserStory {
    private final String CREATE_DESCRIPTION = "Adds a new calendar event";
    private final String CREATE_TAG = "Create event story";
    private final String CREATE_SUCCESS = "CreateEventStory: Event created.";
    private final String CREATE_ERROR = "Create event exception: ";
    private final String DELETE_DESCRIPTION = "Deletes a calendar event";
    private final String DELETE_TAG = "Delete event story";
    private final String DELETE_SUCCESS = "DeleteEventStory: Event deleted.";
    private final String DELETE_ERROR = "Delete event exception: ";

    private String mDescription;
    private String mLogTag;
    private String mSuccessDescription;
    private String mErrorDescription;

    public CreateOrDeleteEventStory(StoryAction action) {
        switch (action) {
            case CREATE: {
                mDescription = CREATE_DESCRIPTION;
                mLogTag = CREATE_TAG;
                mSuccessDescription = CREATE_SUCCESS;
                mErrorDescription = CREATE_ERROR;
                break;
            }
            case DELETE: {
                mDescription = DELETE_DESCRIPTION;
                mLogTag = DELETE_TAG;
                mSuccessDescription = DELETE_SUCCESS;
                mErrorDescription = DELETE_ERROR;
                break;
            }
        }
    }

    @Override
    public String execute() {
        //PREPARE
        AuthenticationController
                .getInstance()
                .setResourceId(
                        super.getO365MailResourceId());

        CalendarSnippets calendarSnippets = new CalendarSnippets(
                getO365MailClient());

        List<String> attendeeEmailAddresses = new ArrayList<>();
        attendeeEmailAddresses.add(GlobalValues.USER_EMAIL);
        String newEventId;
        //ACT
        try {
            newEventId = calendarSnippets.createCalendarEvent(
                    getStringResource(R.string.calendar_subject_text)
                    , getStringResource(R.string.calendar_body_text)
                    , java.util.Calendar.getInstance()
                    , java.util.Calendar.getInstance()
                    , attendeeEmailAddresses);

            //Delete event
            calendarSnippets.deleteCalendarEvent(newEventId);
        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, mLogTag);
        }
        return StoryResultFormatter.wrapResult(mSuccessDescription, true);
    }

    @Override
    public String getDescription() {
        return mDescription;
    }
} public class CreateRecurringEventStory extends BaseUserStory {

    private static final String STORY_DESCRIPTION = "Create a recurring event";

    @Override
    public String execute() {
        boolean isStoryComplete;
        String resultMessage;

        AuthenticationController
                .getInstance()
                .setResourceId(
                        getO365MailResourceId());

        CalendarSnippets calendarSnippets = new CalendarSnippets(
                getO365MailClient());
        List<String> attendeeEmailAdresses = new ArrayList<>();
        attendeeEmailAdresses.add(GlobalValues.USER_EMAIL);

        try {
            //Create a recurring event
            String newEventId = calendarSnippets.createRecurringCalendarEvent(
                    getStringResource(R.string.calendar_subject_text)
                    , getStringResource(R.string.calendar_body_text)
                    , attendeeEmailAdresses);

            //Cleanup by deleting the event
            calendarSnippets.deleteCalendarEvent(newEventId);
            isStoryComplete = true;
            resultMessage = STORY_DESCRIPTION + ": Recurring event created";
        } catch (ExecutionException | InterruptedException e) {
            isStoryComplete = false;
            resultMessage = FormatException(e, STORY_DESCRIPTION);
        }

        return StoryResultFormatter.wrapResult(resultMessage, isStoryComplete);
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class EventsFetcherStory extends BaseUserStory {

    public static final String STORY_DESCRIPTION = "Get calendar events";

    @Override
    public String execute() {
        String returnResult;
        if (getO365MailClient() == null) {
            returnResult = "Null OutlookClient";
        }
        try {
            AuthenticationController
                    .getInstance()
                    .setResourceId(
                            getO365MailResourceId());

            CalendarSnippets calendarSnippets = new CalendarSnippets(
                    getO365MailClient());

            //get the calendar events
            List<Event> events = calendarSnippets.getO365Events();

            //build string for test results on UI
            StringBuilder sb = new StringBuilder();
            sb.append("The following events were retrieved:\n");
            for (Event event : events) {
                sb.append("\t\t" + event.getSubject() + ". " + formatEventDates(event));
                sb.append("\n");
            }
            returnResult = StoryResultFormatter.wrapResult(sb.toString(), true);
        } catch (Exception ex) {
            return FormatException(ex, STORY_DESCRIPTION);
        }
        return returnResult;
    }

    private String formatEventDates(Event thisEvent) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd/yy - hh:ss a", Locale.US);
        return simpleDateFormat.format(thisEvent.getStart().getTime());
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }

} public class RespondToCalendarEventInviteStory extends BaseEmailUserStory {

    private static final String STORY_DESCRIPTION = "Responds to accept an event invite";

    @Override
    public String execute() {
        //PREPARE
        boolean isStoryComplete;
        String resultMessage;
        AuthenticationController
                .getInstance()
                .setResourceId(
                        getO365MailResourceId());

        CalendarSnippets calendarSnippets = new CalendarSnippets(
                getO365MailClient());

        List<String> attendeeEmailAddresses = new ArrayList<>();
        attendeeEmailAddresses.add(GlobalValues.USER_EMAIL);
        String uniqueGUID = java.util.UUID.randomUUID().toString();
        String subjectLine = getStringResource(R.string.calendar_subject_text)
                + ":"
                + uniqueGUID;
        try {
            String newEventId = calendarSnippets.createCalendarEvent(
                    subjectLine
                    , getStringResource(R.string.calendar_body_text)
                    , java.util.Calendar.getInstance()
                    , java.util.Calendar.getInstance()
                    , attendeeEmailAddresses);

            //wait for server to send event invitation
            Thread.sleep(5000);

            if (calendarSnippets.respondToCalendarEventInvite(newEventId
                    , GlobalValues.USER_EMAIL, ResponseType.Accepted) != null) {

                //wait for server to update attendee status in event
                Thread.sleep(5000);
                ResponseType attendeeStatus = calendarSnippets.getEventAttendeeStatus(
                        newEventId
                        , GlobalValues.USER_EMAIL);

                //Validate the attendee status was set to accepted as expected
                if (attendeeStatus == ResponseType.Accepted) {
                    resultMessage = StoryResultFormatter.wrapResult(
                            "Respond to event invite story: Event accepted."
                            , true);
                } else {
                    resultMessage = StoryResultFormatter.wrapResult(
                            "Respond to event invite story: Event response failed. "
                                    + attendeeStatus
                            , false);
                }

                //CLEANUP by cancelling event
                calendarSnippets.deleteCalendarEvent(newEventId);
            } else {
                resultMessage = StoryResultFormatter.wrapResult(
                        "Respond to event invite story: Event is null."
                        , false);
            }
        } catch (ExecutionException | InterruptedException e) {
            resultMessage = FormatException(e, STORY_DESCRIPTION);
        }
        return resultMessage;
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }

} public class UpdateEventStory extends BaseUserStory {


    private static final String STORY_DESCRIPTION = "Update a calendar event";

    @Override
    public String execute() {
        AuthenticationController
                .getInstance()
                .setResourceId(
                        getO365MailResourceId());

        CalendarSnippets calendarSnippets = new CalendarSnippets(getO365MailClient());
        List<String> attendeeEmailAddresses = new ArrayList<>();
        attendeeEmailAddresses.add(GlobalValues.USER_EMAIL);
        String newEventId = "";
        try {
            newEventId = calendarSnippets.createCalendarEvent(
                    getStringResource(R.string.calendar_subject_text)
                    , getStringResource(R.string.calendar_body_text)
                    , java.util.Calendar.getInstance()
                    , java.util.Calendar.getInstance()
                    , attendeeEmailAddresses
            );
            Thread.sleep(20000);
            Event updatedEvent = calendarSnippets.updateCalendarEvent(
                    newEventId
                    , getStringResource(R.string.calendar_subject_text)
                            + " Updated Subject"
                    , false
                    , null
                    , null
                    , null
                    , null
            );
            Thread.sleep(20000);
            String updatedSubject = updatedEvent.getSubject();
            calendarSnippets.deleteCalendarEvent(newEventId);
            if (updatedSubject.equals(getStringResource(R.string.calendar_subject_text)
                    + " Updated Subject")) {
                return StoryResultFormatter.wrapResult(
                        STORY_DESCRIPTION + ": Event "
                                + " updated.", true);
            } else {
                return StoryResultFormatter.wrapResult(
                        STORY_DESCRIPTION + ": Update "
                                + " event.", false);
            }
        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, STORY_DESCRIPTION);
        }
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class CreateOrDeleteContactStory extends BaseUserStory {
    private final String CREATE_DESCRIPTION = "Creates a new contact";
    private final String CREATE_TAG = "Create contact story";
    private final String CREATE_SUCCESS = "CreateContactStory: Contact created.";
    private final String CREATE_ERROR = "Create contact exception: ";
    private final String DELETE_DESCRIPTION = "Deletes a contact";
    private final String DELETE_TAG = "Delete contact story";
    private final String DELETE_SUCCESS = "DeleteContactStory: Contact deleted.";
    private final String DELETE_ERROR = "Delete contact exception: ";

    private String mDescription;
    private String mLogTag;
    private String mSuccessDescription;
    private String mErrorDescription;

    public CreateOrDeleteContactStory(StoryAction action) {
        switch (action) {
            case CREATE: {
                mDescription = CREATE_DESCRIPTION;
                mLogTag = CREATE_TAG;
                mSuccessDescription = CREATE_SUCCESS;
                mErrorDescription = CREATE_ERROR;
                break;
            }
            case DELETE: {
                mDescription = DELETE_DESCRIPTION;
                mLogTag = DELETE_TAG;
                mSuccessDescription = DELETE_SUCCESS;
                mErrorDescription = DELETE_ERROR;
                break;
            }
        }
    }

    @Override
    public String execute() {
        String returnValue = StoryResultFormatter.wrapResult(
                mLogTag, false
        );
        AuthenticationController
                .getInstance()
                .setResourceId(
                        getO365MailResourceId());

        ContactsSnippets contactsSnippets = new ContactsSnippets(getO365MailClient());
        try {
            String contactId = contactsSnippets.createContact(
                    getStringResource(R.string.contacts_email),
                    getStringResource(R.string.contacts_business_phone),
                    getStringResource(R.string.contacts_home_phone),
                    getStringResource(R.string.contacts_first_name),
                    getStringResource(R.string.contacts_last_name));
            if (contactId.length() > 0) {
                contactsSnippets.deleteContact(contactId);
                return StoryResultFormatter.wrapResult(
                        mSuccessDescription, true
                );
            }
        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, mDescription);
        }
        return returnValue;
    }

    @Override
    public String getDescription() {
        return mDescription;
    }

} public class GetContactsStory extends BaseUserStory {

    private static final String STORY_DESCRIPTION = "Gets your contacts";

    @Override
    public String execute() {
        AuthenticationController
                .getInstance()
                .setResourceId(
                        getO365MailResourceId());

        ContactsSnippets contactsSnippets = new ContactsSnippets(
                getO365MailClient());
        try {
            List<Contact> contacts = contactsSnippets.getContacts(11);
            //build string for test results on UI
            StringBuilder sb = new StringBuilder();
            sb.append("Gets contacts: "
                    + contacts.size()
                    + " contacts returned");
            sb.append("\n");
            for (Contact contact : contacts) {
                sb.append("\t\t");
                sb.append(contact.getDisplayName());
                sb.append("\n");
            }
            return StoryResultFormatter.wrapResult(sb.toString(), true);

        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, STORY_DESCRIPTION);
        }
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }


} public class GetFilteredContactsWithSurnameStory extends BaseUserStory {

    private static final String STORY_DESCRIPTION = "Gets contacts filtered by surname";
    private static final String CONTACT_WITH_SURNAME = "Contact with surname";

    @Override
    public String execute() {
        boolean isStoryComplete = false;
        String storyResultText = "";

        String surname = getStringResource(R.string.contacts_last_name);
        AuthenticationController
                .getInstance()
                .setResourceId(getO365MailResourceId());
        ContactsSnippets contactsSnippets = new ContactsSnippets(getO365MailClient());

        try {
            //Create a contact that we can test against
            String contactId = contactsSnippets.createContact(
                    getStringResource(R.string.contacts_email),
                    getStringResource(R.string.contacts_business_phone),
                    getStringResource(R.string.contacts_home_phone),
                    getStringResource(R.string.contacts_first_name),
                    surname);

            //Find the new test contact
            List<Contact> contacts = contactsSnippets.getContactsWithSurname(surname);
            for (Contact contact : contacts) {
                if (contact.getSurname().equals(surname)) {
                    break;
                }
            }
            //Delete the test contact from tenant
            contactsSnippets.deleteContact(contactId);

            //Story is completed
            storyResultText = StoryResultFormatter.wrapResult(CONTACT_WITH_SURNAME
                    + " " + surname
                    + " found.", true);
        } catch (ExecutionException | InterruptedException e) {
            storyResultText = FormatException(e, STORY_DESCRIPTION);
        }
        return storyResultText;
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }


} public class UpdateContactStory extends BaseUserStory {
    private static final String UPDATE_CONTACT_STORY = "Update Contact story";
    private static final String STORY_DESCRIPTION = "Updates the surname of a contact";
    private Context mContext;

    public UpdateContactStory(Context context) {
        mContext = context;
    }

    @Override
    public String execute() {
        String returnValue = "CreateContactStory failed";
        AuthenticationController
                .getInstance()
                .setResourceId(
                        getO365MailResourceId());

        ContactsSnippets contactsSnippets = new ContactsSnippets(getO365MailClient());
        try {
            //Create a new contact to test update API with
            String contactId = contactsSnippets.createContact(
                    mContext.getString(R.string.contacts_email),
                    mContext.getString(R.string.contacts_business_phone),
                    mContext.getString(R.string.contacts_home_phone),
                    mContext.getString(R.string.contacts_first_name),
                    mContext.getString(R.string.contacts_last_name)
            );
            if (contactId.length() > 0) {
                //Set a new surname value on contact to update
                //and update the contact
                String newSurname = "Curtis_2";

                contactsSnippets.updateContact(
                        contactId
                        , mContext.getString(R.string.contacts_first_name)
                        , newSurname
                );

                //Get the updated contact from server and compare surname with
                //the intended update surname value
                Contact updatedContact = contactsSnippets.getAContact(contactId);
                if (updatedContact != null) {
                    String testSurName = updatedContact.getSurname();
                    if (testSurName.length() > 0 && testSurName.equals(newSurname)) {
                        returnValue = StoryResultFormatter.wrapResult(
                                "UpdateContactStory: Contact "
                                        + " updated."
                                , true
                        );
                    } else {
                        returnValue = StoryResultFormatter.wrapResult(
                                "UpdateContactStory: Contact "
                                , false
                        );

                    }
                } else {
                    returnValue = StoryResultFormatter.wrapResult(
                            "UpdateContactStory: Contact "
                            , false
                    );

                }
                //Clean up state
                contactsSnippets.deleteContact(contactId);
                return returnValue;
            }
        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, UPDATE_CONTACT_STORY);
        }
        return returnValue;
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class DeleteEmailAttachmentStory extends  BaseEmailUserStory{

    private static final String SENT_NOTICE = "Attachment email sent with subject line:";
    private static final String STORY_DESCRIPTION = "Deletes an attachment from a draft email message";

    @Override
    public String execute() {
        StringBuilder returnResult = new StringBuilder();
        try {
            AuthenticationController
                    .getInstance()
                    .setResourceId(
                            getO365MailResourceId());

            EmailSnippets emailSnippets = new EmailSnippets(
                    getO365MailClient());

            //1. Add an email to draft folder and store the ID
            String uniqueGUID = java.util.UUID.randomUUID().toString();
            String mailSubject = getStringResource(R.string.mail_subject_text) + uniqueGUID;

            //Add a new email to the user's draft folder
            String emailID = emailSnippets.addDraftMail(GlobalValues.USER_EMAIL,
                    mailSubject,
                    getStringResource(R.string.mail_body_text));

            //Add a text file attachment to the mail added to the draft folder
            emailSnippets.addTextFileAttachmentToMessage(emailID
                    , getStringResource(R.string.text_attachment_contents)
                    , getStringResource(R.string.text_attachment_filename)
                    , false);

            StringBuilder sb = new StringBuilder();
            sb.append(SENT_NOTICE);
            sb.append(getStringResource(R.string.mail_subject_text));
            sb.append(uniqueGUID);

            if (emailID.length() > 0) {
                emailSnippets.removeEmailAttachments(emailID);

                returnResult.append(StoryResultFormatter.wrapResult(sb.toString(), true));
            } else
                returnResult.append(StoryResultFormatter.wrapResult(sb.toString(), false)) ;


        } catch (ExecutionException | InterruptedException  ex) {
            returnResult.append(FormatException(ex, STORY_DESCRIPTION)) ;
        }
        return returnResult.toString();
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class ForwardEmailMessageStory extends BaseEmailUserStory {

    private static final String STORY_DESCRIPTION = "Forward a draft email message";

    @Override
    public String execute() {
        AuthenticationController
                .getInstance()
                .setResourceId(
                        getO365MailResourceId());

        try {
            EmailSnippets emailSnippets = new EmailSnippets(
                    getO365MailClient());

            //1. Send an email and store the ID
            String uniqueGUID = java.util.UUID.randomUUID().toString();
            emailSnippets.createAndSendMail(
                    GlobalValues.USER_EMAIL
                    , getStringResource(R.string.mail_subject_text)
                            + uniqueGUID, getStringResource(R.string.mail_body_text));

            //Get the new message
            Message messageToForward = GetAMessageFromEmailFolder(emailSnippets,
                    getStringResource(R.string.mail_subject_text)
                            + uniqueGUID, getStringResource(R.string.Email_Folder_Inbox));

            String forwardEmailId = emailSnippets.forwardDraftMail(messageToForward.getId(),GlobalValues.USER_EMAIL);

            //3. Delete the email using the ID
            emailSnippets.deleteMail(messageToForward.getId());
            if (forwardEmailId.length() > 0) {
                emailSnippets.deleteMail(forwardEmailId);
            }

            return StoryResultFormatter.wrapResult(
                    STORY_DESCRIPTION, true
            );
        } catch (ExecutionException | InterruptedException ex) {
            return FormatException(ex, STORY_DESCRIPTION);
        }
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }

} public class GetEmailAttachmentsStory extends BaseEmailUserStory {
    private static final String SENT_NOTICE = "Attachment email sent with subject line:";
    private static final boolean IS_INLINE = false;
    private static final String STORY_DESCRIPTION = "Gets the attachments from an email message";

    @Override
    public String execute() {
        String returnResult = "";
        try {
            AuthenticationController
                    .getInstance()
                    .setResourceId(
                            getO365MailResourceId());

            EmailSnippets emailSnippets = new EmailSnippets(
                    getO365MailClient());
            //1. Send an email and store the ID
            String uniqueGUID = java.util.UUID.randomUUID().toString();
            String mailSubject = getStringResource(R.string.mail_subject_text) + uniqueGUID;

            //Add a new email to the user's draft folder
            String emailID = emailSnippets.addDraftMail(GlobalValues.USER_EMAIL,
                    mailSubject,
                    getStringResource(R.string.mail_body_text));

            //Add a text file attachment to the mail added to the draft folder
            emailSnippets.addTextFileAttachmentToMessage(emailID
                    , getStringResource(R.string.text_attachment_contents)
                    , getStringResource(R.string.text_attachment_filename)
                    , IS_INLINE);

            String draftMessageID = emailSnippets.getMailMessageById(emailID).getId();

            //Send the draft email to the recipient
            emailSnippets.sendMail(draftMessageID);

            //Get the new message
            Message sentMessage = GetAMessageFromEmailFolder(emailSnippets,
                    getStringResource(R.string.mail_subject_text)
                            + uniqueGUID, getStringResource(R.string.Email_Folder_Inbox));


            StringBuilder sb = new StringBuilder();
            sb.append(SENT_NOTICE);
            sb.append(getStringResource(R.string.mail_subject_text) + uniqueGUID);
            if (sentMessage.getId().length() > 0) {
                List<Attachment> attachments = emailSnippets.getAttachmentsFromEmailMessage(
                        sentMessage.getId());
                //Send the mail with attachments
                //build string for test results on UI
                for (Attachment attachment : attachments) {
                    if (attachment instanceof FileAttachment) {
                        FileAttachment fileAttachment = (FileAttachment) attachment;
                        String fileContents = new String(fileAttachment.getContentBytes(), "UTF-8");
                        sb.append(fileContents);
                        sb.append("/n");
                    }
                }
                returnResult = StoryResultFormatter.wrapResult(sb.toString(), true);
            } else
                returnResult = StoryResultFormatter.wrapResult(sb.toString(), false);


            //3. Delete the email using the ID
            // Boolean result = emailSnippets.deleteMail(emailID);

        } catch (ExecutionException | InterruptedException | UnsupportedEncodingException ex) {
            return FormatException(ex, STORY_DESCRIPTION);
        }
        return returnResult;

    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class GetEmailMessagesStory extends BaseEmailUserStory {

    private static final String STORY_DESCRIPTION = "Gets 10 newest email messages";

    @Override
    public String execute() {
        String returnResult;

        AuthenticationController
                .getInstance()
                .setResourceId(
                        getO365MailResourceId());

        try {

            EmailSnippets emailSnippets = new EmailSnippets(
                    getO365MailClient());

            //O365 API called in this helper
            List<Message> messages = emailSnippets.getMailMessages();

            //build string for test results on UI
            StringBuilder sb = new StringBuilder();
            sb.append("Gets email: " + messages.size() + " messages returned");
            sb.append("\n");
            for (Message m : messages) {
                sb.append("\t\t");
                sb.append(m.getSubject());
                sb.append("\n");
            }
            returnResult = StoryResultFormatter.wrapResult(sb.toString(), true);
        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, STORY_DESCRIPTION);
        }
        return returnResult;
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class ReplyToEmailMessageStory extends BaseEmailUserStory {


    private static final String STORY_DESCRIPTION = "Reply to an email message";

    @Override
    public String execute() {

        AuthenticationController
                .getInstance()
                .setResourceId(
                        getO365MailResourceId());

        try {
            EmailSnippets emailSnippets = new EmailSnippets(
                    getO365MailClient());

            //1. Send an email and store the ID
            String uniqueGUID = java.util.UUID.randomUUID().toString();
            emailSnippets.createAndSendMail(
                    GlobalValues.USER_EMAIL
                    , getStringResource(R.string.mail_subject_text)
                            + uniqueGUID
                    , getStringResource(R.string.mail_body_text));

            //Get the new message
            Message message = GetAMessageFromEmailFolder(emailSnippets,
                    getStringResource(R.string.mail_subject_text)
                            + uniqueGUID, getStringResource(R.string.Email_Folder_Inbox));

            if (message.getId().length() > 0) {
                String replyEmailId = emailSnippets.replyToEmailMessage(
                        message.getId()
                        , getStringResource(R.string.mail_body_text));
                //3. Delete the email using the ID
                emailSnippets.deleteMail(message.getId());
                if (replyEmailId.length() > 0) {
                    emailSnippets.deleteMail(replyEmailId);
                }
                return StoryResultFormatter.wrapResult(
                        STORY_DESCRIPTION + ":", true);
            } else {
                return StoryResultFormatter.wrapResult(
                        STORY_DESCRIPTION + ":", false);
            }
        } catch (ExecutionException | InterruptedException ex) {
            return FormatException(ex, STORY_DESCRIPTION);
        }
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class SendEmailMessageStory extends BaseEmailUserStory {

    private static final String STORY_DESCRIPTION = "Sends an email message";

    @Override
    public String execute() {
        String returnResult;
        try {

            AuthenticationController
                    .getInstance()
                    .setResourceId(
                            getO365MailResourceId());

            EmailSnippets emailSnippets = new EmailSnippets(
                    getO365MailClient());

            //1. Send an email and store the ID
            String uniqueGUID = java.util.UUID.randomUUID().toString();
            String subject = getStringResource(R.string.mail_subject_text) + uniqueGUID;
            emailSnippets.createAndSendMail(GlobalValues.USER_EMAIL,
                    subject,
                    getStringResource(R.string.mail_body_text));

            //3. Delete the email using the ID
            Message message = GetAMessageFromEmailFolder(emailSnippets, subject, getStringResource(R.string.Email_Folder_Inbox));
            emailSnippets.deleteMail(message.getId());

            returnResult = StoryResultFormatter.wrapResult("Email is added", true);
        } catch (Exception e) {
            return FormatException(e, STORY_DESCRIPTION);
        }
        return returnResult;
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }


} public class SendEmailWithMessageAttachStory extends BaseEmailUserStory {

    private static final String STORY_DESCRIPTION = "Sends an email message with a message attachment";
    private static final String SENT_NOTICE = "Email sent with subject line:";
    private static final boolean IS_INLINE = false;


    @Override
    public String execute() {
        String returnResult = "";
        try {
            AuthenticationController
                    .getInstance()
                    .setResourceId(
                            getO365MailResourceId());

            EmailSnippets emailSnippets = new EmailSnippets(
                    getO365MailClient());

            //1. Send an email and store the ID
            String uniqueGUID = java.util.UUID.randomUUID().toString();
            emailSnippets.createAndSendMail(
                    GlobalValues.USER_EMAIL
                    , getStringResource(R.string.mail_subject_text)
                            + uniqueGUID, getStringResource(R.string.mail_body_text));


            Message messageToAttach = GetAMessageFromEmailFolder(emailSnippets,
                    getStringResource(R.string.mail_subject_text)
                            + uniqueGUID, getStringResource(R.string.Email_Folder_Inbox));

            if (messageToAttach != null) {
                //Create a new email message but do not send yet
                String newEmailId = emailSnippets.addDraftMail(
                        GlobalValues.USER_EMAIL
                        , getStringResource(R.string.mail_subject_text) + uniqueGUID
                        , getStringResource(R.string.mail_body_text));

                //Attach email message to new draft email
                emailSnippets.addItemAttachment(
                        newEmailId
                        , messageToAttach
                        , IS_INLINE);

                //Send draft email
                emailSnippets.sendMail(newEmailId);

                DeleteAMessageFromMailFolder(emailSnippets,
                        getStringResource(R.string.mail_subject_text)
                                + uniqueGUID,
                        getStringResource(R.string.Email_Folder_Sent));

                returnResult = StoryResultFormatter.wrapResult(
                        SENT_NOTICE
                                + " "
                                + getStringResource(R.string.mail_subject_text)
                        , true);
            }


        } catch (Exception ex) {
            return FormatException(ex, STORY_DESCRIPTION);
        }
        return returnResult;
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class SendEmailWithTextFileAttachmentStory extends BaseEmailUserStory {

    private static final String STORY_DESCRIPTION = "Sends an email message with a text file attachment";
    private static final String SENT_NOTICE = "Email sent with subject line:";
    private static final boolean IS_INLINE = false;

    @Override
    public String execute() {
        String returnResult;
        try {
            AuthenticationController
                    .getInstance()
                    .setResourceId(
                            getO365MailResourceId());

            EmailSnippets emailSnippets = new EmailSnippets(
                    getO365MailClient());

            //1. Send an email and store the ID
            String uniqueGUID = java.util.UUID.randomUUID().toString();

            //Add a new email to the user's draft folder
            String emailID = emailSnippets.addDraftMail(GlobalValues.USER_EMAIL,
                    getStringResource(R.string.mail_subject_text) + uniqueGUID,
                    getStringResource(R.string.mail_body_text));

            //Add a text file attachment to the mail added to the draft folder
            emailSnippets.addTextFileAttachmentToMessage(emailID
                    , getStringResource(R.string.text_attachment_contents)
                    , getStringResource(R.string.text_attachment_filename)
                    , IS_INLINE);

            String draftMessageID = emailSnippets.getMailMessageById(emailID).getId();

            //Send the mail with attachments
            returnResult = StoryResultFormatter.wrapResult(
                    SENT_NOTICE
                            + getStringResource(R.string.mail_subject_text)
                            + uniqueGUID
                    , true);

            //Send the draft email to the recipient
            emailSnippets.sendMail(draftMessageID);

        } catch (Exception ex) {
            return FormatException(ex, STORY_DESCRIPTION);
        }
        return returnResult;
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class CreateOrDeleteFileStory extends BaseUserStory {
    private final String CREATE_DESCRIPTION = "Create a file on server";
    private final String CREATE_TAG = "CreateFile";
    private final String CREATE_SUCCESS = "Create a file on server";
    private final String CREATE_ERROR = "Create a file on server exception: ";

    private final String DELETE_DESCRIPTION = "Delete a file on server";
    private final String DELETE_TAG = "DeleteFile";
    private final String DELETE_SUCCESS = "Delete a file on server";
    private final String DELETE_ERROR = "Delete a file on server exception: ";

    private String mDescription;
    private String mLogTag;
    private String mSuccessDescription;
    private String mErrorDescription;

    public CreateOrDeleteFileStory(StoryAction action) {
        switch (action) {
            case CREATE: {
                mDescription = CREATE_DESCRIPTION;
                mLogTag = CREATE_TAG;
                mSuccessDescription = CREATE_SUCCESS;
                mErrorDescription = CREATE_ERROR;
                break;
            }
            case DELETE: {
                mDescription = DELETE_DESCRIPTION;
                mLogTag = DELETE_TAG;
                mSuccessDescription = DELETE_SUCCESS;
                mErrorDescription = DELETE_ERROR;
                break;
            }
        }
    }

    @Override
    public String execute() {
        AuthenticationController
                .getInstance()
                .setResourceId(
                        getFilesFoldersResourceId());
        FileFolderSnippets fileFolderSnippets = new FileFolderSnippets(
                getO365MyFilesClient());

        try {

            String fileContents = "Test create and delete file";
            //Create file
            String newFileId = fileFolderSnippets
                    .postNewFileToServer(
                            "test_Create_Delete_"
                                    + java
                                    .util
                                    .UUID
                                    .randomUUID()
                                    .toString()
                                    + ".txt"
                            , fileContents.getBytes(Charsets.UTF_8));

            //Delete file
            fileFolderSnippets.deleteFileFromServer(newFileId);
            return StoryResultFormatter.wrapResult(mSuccessDescription, true);
        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, mDescription);
        }
    }

    @Override
    public String getDescription() {
        return mDescription;
    }
} public class CreateOrDeleteOneDriveFolder extends BaseUserStory {
    //Unique names used for tracking and cleanup of items created by running snippets
    private static final String FOLDER_NAME = "O365SnippetFolder_";
    private final String CREATE_DESCRIPTION = "Create new folder on OneDrive";
    private final String CREATE_SUCCESS = "OneDrive create folder story: Folder created.";
    private final String DELETE_DESCRIPTION = "Delete folder from OneDrive";
    private final String DELETE_SUCCESS = "OneDrive delete folder story: Folder deleted.";
    private String mDescription;
    private String mSuccessDescription;

    public CreateOrDeleteOneDriveFolder(StoryAction action) {
        switch (action) {
            case CREATE: {
                mDescription = CREATE_DESCRIPTION;
                mSuccessDescription = CREATE_SUCCESS;
                break;
            }
            case DELETE: {
                mDescription = DELETE_DESCRIPTION;
                mSuccessDescription = DELETE_SUCCESS;
                break;
            }
        }
    }

    @Override
    public String execute() {
        AuthenticationController
                .getInstance()
                .setResourceId(
                        getFilesFoldersResourceId());
        FileFolderSnippets fileFolderSnippets = new FileFolderSnippets(getO365MyFilesClient());

        try {
            String folderName = FOLDER_NAME + java
                    .util
                    .UUID
                    .randomUUID()
                    .toString();

            //Create folder
            fileFolderSnippets.createO365Folder(folderName);

            //Delete folder
            fileFolderSnippets.deleteO365Folder(folderName);

            return StoryResultFormatter.wrapResult(
                    mSuccessDescription, true);

        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, mDescription);
        }
    }

    @Override
    public String getDescription() {
        return mDescription;
    }

} public class DownloadFileStory extends BaseUserStory {
    private static final String DOWNLOAD_DOC_PATH = "O365Snippets";
    private static final String DOWNLOAD_DOC_FILENAME = "testdownload.txt";
    private static final String FILE_CONTENTS = "Test download file contents";
    private static final String STORY_DESCRIPTION = "Download a file from MyFiles";
    private boolean mFolderCreated = false;

    @Override
    public String execute() {
        AuthenticationController
                .getInstance()
                .setResourceId(
                        getFilesFoldersResourceId());
        FileFolderSnippets fileFolderSnippets = new FileFolderSnippets(
                getO365MyFilesClient());
        try {
            String fileContents = FILE_CONTENTS;
            String itemId;

            //Remove test text file from server if left by previous execute()
            itemId = fileFolderSnippets.getFileFromServerByName(DOWNLOAD_DOC_FILENAME);
            if (itemId.length() != 0) {
                //Remove remote file instance
                fileFolderSnippets.deleteFileFromServer(itemId);
            }
            String newFileId = fileFolderSnippets
                    .postNewFileToServer(
                            DOWNLOAD_DOC_FILENAME
                            , fileContents.getBytes());


            byte[] fileContentsBytes = fileFolderSnippets.getFileContentsFromServer(newFileId);

            //Remove remote file instance
            fileFolderSnippets.deleteFileFromServer(newFileId);

            //Save file locally
            if (saveFileInExternalStorage(DOWNLOAD_DOC_FILENAME, fileContentsBytes)) {

                //Verify local file exists and then remove it
                if (verifyFileInExternalStorage(DOWNLOAD_DOC_FILENAME))
                    return StoryResultFormatter.wrapResult(STORY_DESCRIPTION, true);
                else
                    return StoryResultFormatter.wrapResult(STORY_DESCRIPTION, false);

            } else
                return StoryResultFormatter.wrapResult(STORY_DESCRIPTION, false);
        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, STORY_DESCRIPTION);
        }
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }


    //Verifies that the downloaded file is saved in external storage and
    //then deletes the downloaded file and the folder that it is saved in
    private boolean verifyFileInExternalStorage(String fileName) {
        boolean fileExistsFlag = false;
        File fileDocDir = verifyDownloadFolder();
        if (fileDocDir == null) return fileExistsFlag;

        final File downloadedFile = new File(fileDocDir.getPath(), fileName);
        if (downloadedFile.exists()) {
            fileExistsFlag = deleteDownloadedFileandFolder(downloadedFile, fileDocDir);
        }
        return fileExistsFlag;
    }

    //Delete the passed file and folder from external storage
    private boolean deleteDownloadedFileandFolder(File downloadedFile, File fileDocDir) {
        if (downloadedFile.exists()) {
            downloadedFile.delete();
            if (mFolderCreated) {
                fileDocDir.delete();
            }
            return true;
        }
        return false;
    }

    private boolean saveFileInExternalStorage(String fileName, final byte[] fileContents) {
        File fileDocDir = verifyDownloadFolder();
        if (fileDocDir == null) return false;

        if (!fileDocDir.exists() && (!fileDocDir.mkdirs())) {
            Log.e("IO error", "Directory not created");
            return false;
        } else {
            final File downloadedFile = new File(fileDocDir.getPath(), fileName);
            if (downloadedFile.exists()) downloadedFile.delete();
            writeFileOut(downloadedFile, fileContents);
            return true;
        }
    }

    private void writeFileOut(File downloadedFile, byte[] filecontent) {
        try {
            FileOutputStream outputStream = new FileOutputStream(downloadedFile);
            try {
                outputStream.write(filecontent);
            } finally {
                outputStream.close();
            }
        } catch (IOException io) {
            Log.e(
                    "File IO ERROR"
                    , "The file was not saved "
                            + io.getMessage()
            );
        }
    }

    private File verifyDownloadFolder() {
        File fileDocDir = null;
        String externalStorageState = Environment.getExternalStorageState();
        if (Environment.MEDIA_MOUNTED.equals(externalStorageState)) {
            fileDocDir = new File(
                    Environment
                            .getExternalStorageDirectory().getPath(), DOWNLOAD_DOC_PATH
            );

            if (!fileDocDir.exists()) {
                mFolderCreated = true;
                fileDocDir.mkdirs();
            }
        }
        return fileDocDir;
    }
} public class GetFilesAndFoldersStory extends BaseUserStory {

    private static final String STORY_DESCRIPTION = "Gets files and folders from user's OneDrive";

    @Override
    public String execute() {
        AuthenticationController
                .getInstance()
                .setResourceId(
                        getFilesFoldersResourceId());

        FileFolderSnippets fileFolderSnippets = new FileFolderSnippets(
                getO365MyFilesClient());
        try {
            List<Item> items = fileFolderSnippets.getFilesAndFolders();
            //build string for test results on UI
            StringBuilder sb = new StringBuilder();
            sb.append("Gets items: "
                    + items.size()
                    + " items returned");
            sb.append("\n");
            for (Item item : items) {
                sb.append("\t\t");
                sb.append(item.gettype() + ": " + item.getname());
                sb.append("\n");
            }
            return StoryResultFormatter.wrapResult(sb.toString(), true);

        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, STORY_DESCRIPTION);
        }
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }

} public class UpdateFileContentsOnServerStory extends BaseUserStory {

    private static final String STORY_DESCRIPTION = "Update file contents on user's OneDrive";

    @Override
    public String execute() {
        AuthenticationController
                .getInstance()
                .setResourceId(
                        getFilesFoldersResourceId());
        FileFolderSnippets fileFolderSnippets = new FileFolderSnippets(
                getO365MyFilesClient());
        try {

            String fileContents = "Test create file";
            String newFileId = fileFolderSnippets
                    .postNewFileToServer(
                            "test_Update_"
                                    + java
                                    .util
                                    .UUID
                                    .randomUUID()
                                    .toString()
                                    + ".txt"
                            , fileContents.getBytes(Charsets.UTF_8));


            String updatedFileContents = fileContents + " updated";
            fileFolderSnippets.postUpdatedFileToServer(newFileId, updatedFileContents);
            byte[] fileContentsBytes = fileFolderSnippets.getFileContentsFromServer(newFileId);
            fileFolderSnippets.deleteFileFromServer(newFileId);

            if (fileContentsBytes.length == updatedFileContents.length()) {
                return StoryResultFormatter.wrapResult(STORY_DESCRIPTION, true);
            } else {
                return StoryResultFormatter.wrapResult(STORY_DESCRIPTION, false);
            }

        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, STORY_DESCRIPTION);
        }
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class ODataFilterStory extends BaseUserStory {
    private static final String STORY_DESCRIPTION = "Use $filter to get events filtered by most important";

    @Override
    public String execute() {
        boolean isSucceeding;
        AuthenticationController
                .getInstance()
                .setResourceId(getO365MailResourceId());
        CalendarSnippets calendarSnippets = new CalendarSnippets(getO365MailClient());
        ODataSystemQuerySnippets oDataSystemQuerySnippets = new ODataSystemQuerySnippets();

        try {
            //Set up one important event to test with
            Event testEvent = new Event();
            testEvent.setSubject(getStringResource(R.string.calendar_subject_text));

            //Set body on test event
            ItemBody itemBody = new ItemBody();
            itemBody.setContent(getStringResource(R.string.calendar_body_text));
            itemBody.setContentType(BodyType.HTML);
            testEvent.setBody(itemBody);

            //Set start and end time for event
            Calendar eventTime = Calendar.getInstance();
            testEvent.setStart(eventTime);
            eventTime.add(Calendar.HOUR_OF_DAY, 2);
            testEvent.setIsAllDay(false);
            testEvent.setEnd(eventTime);
            testEvent.setImportance(Importance.High);

            //Create test event on tenant
            testEvent = calendarSnippets.createCalendarEvent(testEvent);

            //Retrieve important events (should include our test event)
            List<Event> importantEvents = oDataSystemQuerySnippets.getImportantEventsUsing$filter(getO365MailClient());

            //Check that all events are important to determine if story succeeded.
            isSucceeding = true;
            for (Event event : importantEvents) {
                if (event.getImportance() != Importance.High) {
                    isSucceeding = false;
                    break;
                }
            }

            //Delete test event from tenant
            calendarSnippets.deleteCalendarEvent(testEvent.getId());

        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, STORY_DESCRIPTION);
        }
        if (isSucceeding) {
            return StoryResultFormatter.wrapResult(STORY_DESCRIPTION + ": Important events found.", true);
        } else {
            return StoryResultFormatter.wrapResult(STORY_DESCRIPTION + ": Important events not found.", false);
        }
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }


} public class ODataSelectStory extends BaseUserStory {
    private static final String STORY_DESCRIPTION = "Use $select to reduce payload when getting messages";

    @Override
    public String execute() {
        boolean isStoryComplete = false;
        StringBuilder returnResult = new StringBuilder();

        AuthenticationController
                .getInstance()
                .setResourceId(
                        getO365MailResourceId());
        try {
            ODataSystemQuerySnippets oDataSystemQuerySnippets = new ODataSystemQuerySnippets();

            //O365 API called in this helper
            List<Message> messages = oDataSystemQuerySnippets.getMailMessagesUsing$select(getO365MailClient());

            returnResult.append(STORY_DESCRIPTION)
                    .append(": ")
                    .append(messages.size())
                    .append(" messages returned")
                    .append("\n");

            for (Message message : messages) {
                returnResult.append("\t\tFrom: ")
                        .append(message.getFrom())
                        .append("\n\t\tIs Read: ")
                        .append(message.getIsRead().toString())
                        .append("\n\t\tSubject: ")
                        .append(message.getSubject())
                        .append("\n");
            }
            isStoryComplete = true;
        } catch (ExecutionException | InterruptedException e) {
            isStoryComplete = false;
            e.printStackTrace();
            String formattedException = APIErrorMessageHelper.getErrorMessage(e.getMessage());
            Log.e("Get email story", formattedException);
            returnResult = new StringBuilder();
            returnResult.append(STORY_DESCRIPTION)
                    .append(": ")
                    .append(formattedException);
        }
        return StoryResultFormatter.wrapResult(returnResult.toString(), isStoryComplete);
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class GetADGroupsStory extends BaseUserStory {

    private static final String STORY_DESCRIPTION = "Gets groups from Active Directory";

    @Override
    public String execute() {
        boolean isStoryComplete;
        StringBuilder resultMessage = new StringBuilder();

        AuthenticationController
                .getInstance()
                .setResourceId(Constants.DIRECTORY_RESOURCE_ID);
        DirectoryClient directoryClient = O365ServicesManager.getDirectoryClient();
        if (directoryClient == null)
            return StoryResultFormatter.wrapResult("Tenant ID was null", false);

        UsersAndGroupsSnippets usersAndGroupsSnippets = new UsersAndGroupsSnippets(directoryClient);

        try {
            //Get list of groups
            List<Group> groupList;
            groupList = usersAndGroupsSnippets.getGroups();
            if (groupList == null) {
                //No groups were found
                resultMessage.append("Get Active Directory Groups: No groups found");
            } else {
                resultMessage.append("Get Active Directory Groups: The following groups were found:\n");
                for (Group group : groupList) {
                    resultMessage.append(group.getdisplayName())
                            .append("\n");
                }
            }
            isStoryComplete = true;
        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, STORY_DESCRIPTION);
        }
        return StoryResultFormatter.wrapResult(resultMessage.toString(), isStoryComplete);
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class GetADUsersStory extends BaseUserStory {

    private static final String STORY_DESCRIPTION = "Gets users from Active Directory";

    @Override
    public String execute() {
        boolean isStoryComplete;
        StringBuilder resultMessage = new StringBuilder();

        AuthenticationController
                .getInstance()
                .setResourceId(Constants.DIRECTORY_RESOURCE_ID);
        DirectoryClient directoryClient = O365ServicesManager.getDirectoryClient();
        if (directoryClient == null)
            return StoryResultFormatter.wrapResult("Tenant ID was null", false);
        UsersAndGroupsSnippets usersAndGroupsSnippets = new UsersAndGroupsSnippets(directoryClient);

        try {
            //Get list of users
            List<User> userList = usersAndGroupsSnippets.getUsers();
            if (userList == null) {
                //No users were found
                resultMessage.append(STORY_DESCRIPTION);
                resultMessage.append(": No users found.");
            } else {
                resultMessage.append(STORY_DESCRIPTION);
                resultMessage.append(": The following users were found:\n");
                for (User user : userList) {
                    resultMessage.append(user.getdisplayName())
                            .append("\n");
                }
            }
            isStoryComplete = true;
        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, STORY_DESCRIPTION);
        }
        return StoryResultFormatter.wrapResult(resultMessage.toString(), isStoryComplete);
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
} public class GetTenantDetailsStory extends BaseUserStory {

    private static final String STORY_DESCRIPTION = "Gets the tenant details from Active Directory";

    @Override
    public String execute() {
        StringBuilder results = new StringBuilder();
        AuthenticationController
                .getInstance()
                .setResourceId(Constants.DIRECTORY_RESOURCE_ID);
        DirectoryClient directoryClient = O365ServicesManager.getDirectoryClient();
        if (directoryClient == null)
            return StoryResultFormatter.wrapResult("Tenant ID was null", false);

        UsersAndGroupsSnippets usersAndGroupsSnippets = new UsersAndGroupsSnippets(directoryClient);
        TenantDetail tenant;
        try {
            tenant = usersAndGroupsSnippets.getTenantDetails();
        } catch (ExecutionException | InterruptedException e) {
            return FormatException(e, STORY_DESCRIPTION);
        }

        if (tenant == null) {
            //No tenants were found
            return StoryResultFormatter.wrapResult(STORY_DESCRIPTION + ": No tenant found", false);
        }
        results.append(STORY_DESCRIPTION);
        results.append(": The following tenant was found:\n");
        results.append(tenant.getdisplayName())
                .append("\n");
        return StoryResultFormatter.wrapResult(results.toString(), true);
    }

    @Override
    public String getDescription() {
        return STORY_DESCRIPTION;
    }
}
import android.content.Context;
import com.microsoft.office365.snippetapp.CalendarStories.CreateOrDeleteEventStory;
import com.microsoft.office365.snippetapp.CalendarStories.CreateRecurringEventStory;
import com.microsoft.office365.snippetapp.CalendarStories.EventsFetcherStory;
import com.microsoft.office365.snippetapp.CalendarStories.RespondToCalendarEventInviteStory;
import com.microsoft.office365.snippetapp.CalendarStories.UpdateEventStory;
import com.microsoft.office365.snippetapp.ContactStories.CreateOrDeleteContactStory;
import com.microsoft.office365.snippetapp.ContactStories.GetContactsStory;
import com.microsoft.office365.snippetapp.ContactStories.GetFilteredContactsWithSurnameStory;
import com.microsoft.office365.snippetapp.ContactStories.UpdateContactStory;
import com.microsoft.office365.snippetapp.EmailStories.DeleteEmailAttachmentStory;
import com.microsoft.office365.snippetapp.EmailStories.ForwardEmailMessageStory;
import com.microsoft.office365.snippetapp.EmailStories.GetEmailAttachmentsStory;
import com.microsoft.office365.snippetapp.EmailStories.GetEmailMessagesStory;
import com.microsoft.office365.snippetapp.EmailStories.ReplyToEmailMessageStory;
import com.microsoft.office365.snippetapp.EmailStories.SendEmailMessageStory;
import com.microsoft.office365.snippetapp.EmailStories.SendEmailWithMessageAttachStory;
import com.microsoft.office365.snippetapp.EmailStories.SendEmailWithTextFileAttachmentStory;
import com.microsoft.office365.snippetapp.FileFolderStories.CreateOrDeleteFileStory;
import com.microsoft.office365.snippetapp.FileFolderStories.CreateOrDeleteOneDriveFolder;
import com.microsoft.office365.snippetapp.FileFolderStories.DownloadFileStory;
import com.microsoft.office365.snippetapp.FileFolderStories.GetFilesAndFoldersStory;
import com.microsoft.office365.snippetapp.FileFolderStories.UpdateFileContentsOnServerStory;
import com.microsoft.office365.snippetapp.ODataStories.ODataFilterStory;
import com.microsoft.office365.snippetapp.ODataStories.ODataSelectStory;
import com.microsoft.office365.snippetapp.R;
import com.microsoft.office365.snippetapp.UserGroupStories.GetADGroupsStory;
import com.microsoft.office365.snippetapp.UserGroupStories.GetADUsersStory;
import com.microsoft.office365.snippetapp.UserGroupStories.GetTenantDetailsStory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
 *  Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file.
 */
package com.microsoft.office365.snippetapp.helpers;




public class StoryList {
    /**
     * An array of story scenarios.
     */
    static final Map<String, BaseUserStory> ITEM_MAP = new HashMap<>();
    /**
     * A map of story scenarios, by ID.
     */
    public List<BaseUserStory> ITEMS = new ArrayList<>();

    /*
    * Add stories to the public story list and story map.
     */
    public StoryList(Context context) {
        List<BaseUserStory> baseUserStories = Arrays.asList(
                //OData system query option stories
                new StoryGroupPlaceholder("OData system query stories"),
                new ODataSelectStory(),
                new ODataFilterStory(),

                //Active Directory Stories
                new StoryGroupPlaceholder(context.getString(R.string.active_directory_group_placeholder)),
                new GetADUsersStory(),
                new GetTenantDetailsStory(),
                new GetADGroupsStory(),

                //Email Stories
                new StoryGroupPlaceholder(context.getString(R.string.email_group_placeholder)),
                new SendEmailMessageStory(),
                new GetEmailMessagesStory(),
                new ReplyToEmailMessageStory(),
                new ForwardEmailMessageStory(),
                new SendEmailWithTextFileAttachmentStory(),
                new SendEmailWithMessageAttachStory(),
                new GetEmailAttachmentsStory(),
                new DeleteEmailAttachmentStory(),

                //Contact Stories
                new StoryGroupPlaceholder(context.getString(R.string.contact_group_placeholder)),
                new GetContactsStory(),
                new CreateOrDeleteContactStory(StoryAction.CREATE),
                new CreateOrDeleteContactStory(StoryAction.DELETE),
                new UpdateContactStory(context),
                new GetFilteredContactsWithSurnameStory(),

                //Calendar Stories
                new StoryGroupPlaceholder(context.getString(R.string.calendar_group_placeholder)),
                new CreateOrDeleteEventStory(StoryAction.CREATE),
                new CreateOrDeleteEventStory(StoryAction.DELETE),
                new EventsFetcherStory(),
                new UpdateEventStory(),
                new RespondToCalendarEventInviteStory(),
                new CreateRecurringEventStory(),

                //Files and Folders Stories
                new StoryGroupPlaceholder(context.getString(R.string.file_folder_group_placeholder)),
                new GetFilesAndFoldersStory(),
                new CreateOrDeleteFileStory(StoryAction.CREATE),
                new UpdateFileContentsOnServerStory(),
                new CreateOrDeleteFileStory(StoryAction.DELETE),
                new DownloadFileStory(),
                new CreateOrDeleteOneDriveFolder(StoryAction.CREATE),