//
//  ScheduleReminderOfferPage.swift 
//  Pi 
//  Copyright © 2021 Evidation Health Inc. All rights reserved.
//
//  Contains the variables and methods for schedule reminder offer

import XCTest

class ScheduleReminderOfferPage: BasePage {
    /*
     * Schedule reminder page constants
     */
    let SCHEDULE_REMINDER_OFFER_TITLE = "Set up reminders"
    let SCHEDULE_REMINDER_OFFFER_DETAILS = "Don’t miss a session by setting up times that work for you."
    
    let SCHEDULE_REMINDER_INTRO_PAGE_TITLE = "Schedule reminders"
    let SCHEDULE_REMINDER_INTRO_PAGE_DETAILS = "You can complete activities at anytime"
    
    let SCHEDULE_REMINDER_NOTIFICATIONS_PAGE_TITLE = "Allow notifications"
    let SCHEDULE_REMINDER_NOTIFICATIONS_PAGE_DETAILS = "To get reminders"
    
    let SCHEDULE_REMINDER_TIPS_PAGE_TITLE = "Some tips"
    let SCHEDULE_REMINDER_TIPS_PAGE_DETAILS = "The activities will take a 2-3 minutes of focus"
    
    let SCHEDULE_REMINDER_SCHEDULE_PAGE_TITLE = "Set up reminders"
    let SCHEDULE_REMINDER_SCHEDULE_PAGE_DETAILS = "For each session"
    
    let REMINDER_COMPLETED_PAGE_TITLE = "Reminders completed"
    let REMINDER_COMPLETED_PAGE_TEXT = "Your schedule is set for the Seasonal Challenge next week."
    
    /*
     * Method assertScheduleReminderOffer is to assert the presence of schedule reminder offer
     */
    func assertScheduleReminderOffer(position: Int) {
        swipeToOfferSection(position: position, elementValue: "Start")
        XCTAssert(app.tables.cells.element(boundBy: position).buttons[SCHEDULE_REMINDER_OFFER_TITLE].waitForExistence(timeout: 15))
        XCTAssert(app.tables.cells.element(boundBy: position).buttons[SCHEDULE_REMINDER_OFFFER_DETAILS].exists)
        XCTAssert(app.tables.cells.element(boundBy: position).buttons["Start"].exists)
    }
    
    /*
     * Method enterScheduleReminderOffer is to enter the schedule reminder offer
     */
    func enterScheduleReminderOffer(position: Int) {
        app.tables.cells.element(boundBy: position).buttons["Start"].tap()
    }
    
    /*
     * Method scheduleReminderIntroPage is to continue from the intro page of schedule reminder offer
     */
    func scheduleReminderIntroPage() {
        buttonExists(SCHEDULE_REMINDER_INTRO_PAGE_TITLE, timeout: 10)
        buttonPartialExists(SCHEDULE_REMINDER_INTRO_PAGE_DETAILS)
        tapButtonExists("Set up reminders")
    }
    
    /*
     * Method scheduleReminderNotificationsPage is to continue from notifications page of schedule reminder
     */
    func scheduleReminderNotificationsPage() {
        buttonExists(SCHEDULE_REMINDER_NOTIFICATIONS_PAGE_TITLE, timeout: 10)
        buttonPartialExists(SCHEDULE_REMINDER_NOTIFICATIONS_PAGE_DETAILS)
        if (PiTestBase().iOSVersion >= "15.0") {
            tapButtonExists("Next")
        } else {
            tapButtonExists("Open Settings app")
    }
    }
    
    /*
     * Method scheduleReminderSomeTipsPage is to continue from tips page of schedule reminder
     */
    func scheduleReminderSomeTipsPage() {
        buttonExists(SCHEDULE_REMINDER_TIPS_PAGE_TITLE, timeout: 10)
        buttonPartialExists(SCHEDULE_REMINDER_TIPS_PAGE_DETAILS)
        tapButtonExists("Next")
    }
    
    /*
     * Method scheduleReminderSchedulePage is to continue from set up reminder page
     */
    func scheduleReminderSchedulePage() {
        buttonExists(SCHEDULE_REMINDER_SCHEDULE_PAGE_TITLE, timeout: 10)
        buttonPartialExists(SCHEDULE_REMINDER_SCHEDULE_PAGE_DETAILS)
        tapButtonExists("Confirm")
    }
    
    /*
     * Method offerCompletePage is to complete the offer and exit to actions tab
     */
    func offerCompletePage() {
        buttonExists(REMINDER_COMPLETED_PAGE_TITLE, timeout: 20)
        buttonExists(REMINDER_COMPLETED_PAGE_TEXT)
        tapButtonExists("Done")
    }
    
    /*
     * Method validateScheduleReminderCompletedCard is to validate the completed card for schedule reminder offer
     */
    func validateScheduleReminderCompletedCard(position: Int) {
        staticPartialCellTableExists("COMPLETED", position: position, timeout: 5)
    }
}
