//
//  IntroToSeasonalChallengeOfferPage.swift
//  Pi
//  Copyright © 2021 Evidation Health Inc. All rights reserved.
//
//  Contains the variables and methods for intro to seasonal challenge offer

import XCTest

class IntroToSeasonalChallengeOfferPage: BasePage {
    /*
     * Intro to seasonal challenge page constants
     */
    let INTRO_SEASONAL_CHALLENGE_OFFER_TITLE = "Introducing Seasonal Challenges"
    let INTRO_SEASONAL_CHALLENGE_OFFFER_DETAILS = "Learn about this two-week event where you can earn more points and rewards. Starts next Monday."
    
    let INTRO_PAGE_TTILE = "Seasonal Challenges"
    let INTRO_PAGE_TEXT = "Every 3 months"
    
    let PATTERN_PAGE_TITLE = "Pattern Drawing"
    let PATERN_PAGE_TEXT = "This activity will challenge"
    
    let MEMORY_MATCH_TITLE = "Memory Match"
    let MEMORY_MATCH_TEXT = "Here you’ll be asked to"
    
    let MORE_ACTIVITIES_TITLE = "More activities, more points"
    let MORE_ACTIVITIES_TEXT = "Completing these activities helps"
    
    let SEASONAL_INTRO_COMPLETED_PAGE_TITLE = "Task completed"
    let SEASONAL_INTRO_COMPLETED_PAGE_TEXT = "Look out for a new Seasonal Challenge card on Monday"
    
    /*
     * Method assertIntroToSeasonalOffer is to assert the presence of seasonal intro offer
     */
    func assertIntroToSeasonalOffer(position: Int) {
        swipeToOfferSection(position: position, elementValue: "Learn more")
        XCTAssert(app.tables.cells.element(boundBy: position).buttons[INTRO_SEASONAL_CHALLENGE_OFFER_TITLE].waitForExistence(timeout: 15))
        XCTAssert(app.tables.cells.element(boundBy: position).buttons[INTRO_SEASONAL_CHALLENGE_OFFFER_DETAILS].exists)
        XCTAssert(app.tables.cells.element(boundBy: position).buttons["Learn more"].exists)
    }
    
    /*
     * Method enterIntroToSeasonalOffer is to enter the seasonal intro offer
     */
    func enterIntroToSeasonalOffer(position: Int) {
        app.tables.cells.element(boundBy: position).buttons["Learn more"].tap()
    }
    
    /*
     * Method completeIntroPage is to continue from intro page in seasonal offer
     */
    func completeIntroPage() {
        buttonExists(INTRO_PAGE_TTILE, timeout: 10)
        buttonExists("Cancel")
        buttonPartialExists(INTRO_PAGE_TEXT)
        tapButtonExists("Next")
    }
    
    /*
     * Method completePatternDrawingPage is to continue from pattern page in seasonal offer
     */
    func completePatternDrawingPage() {
        buttonExists(PATTERN_PAGE_TITLE, timeout: 10)
        buttonExists("Cancel")
        buttonPartialExists(PATERN_PAGE_TEXT)
        tapButtonExists("Next")
    }
    
    /*
     * Method completeMemoryMatchPage is to continue from pattern drawing page in seasonal offer
     */
    func completeMemoryMatchPage() {
        buttonExists(MEMORY_MATCH_TITLE, timeout: 10)
        buttonExists("Cancel")
        buttonPartialExists(MEMORY_MATCH_TEXT)
        tapButtonExists("Next")
    }
    
    /*
     * Method completeMoreActivitiesPage is to continue from more activities page in seasonal offer
     */
    func completeMoreActivitiesPage() {
        buttonExists(MORE_ACTIVITIES_TITLE, timeout: 10)
        buttonExists("Cancel")
        buttonPartialExists(MORE_ACTIVITIES_TEXT)
        tapButtonExists("Next")
    }
    
    /*
     * Method offerCompletePage is to complete the offer and exit to actions tab
     */
    func offerCompletePage() {
        buttonExists(SEASONAL_INTRO_COMPLETED_PAGE_TITLE, timeout: 20)
        buttonPartialExists(SEASONAL_INTRO_COMPLETED_PAGE_TEXT)
        tapButtonExists("Done")
    }
    
    /*
     * Method completeIntroToSeasonalOffer is to complete all pages in the intro to seasonal offer
     */
    func completeIntroToSeasonalOffer() {
        completeIntroPage()
        completePatternDrawingPage()
        completeMemoryMatchPage()
        completeMoreActivitiesPage()
        offerCompletePage()
    }
    
    /*
     * Method validateSeasonalOfferCompletedCard is to validate the completed card for seasonal offer
     */
    func validateSeasonalOfferCompletedCard(position: Int) {
        staticPartialCellTableExists("COMPLETED", position: position, timeout: 5)
    }
}

