// Owen Sullivan
// CPSC 1020-010
// Project 1

// COVID-19 isolation self-assessment tool

// Include statements
#include <iostream>
#include <cctype> // toupper() functionality

// Local header files
#include "Date.h"
#include "calcDays.h"

// Namespaces
using namespace std;

int main() { // Start main function

    // Print program information
    cout << "University COVID-19 isolation self-assessment tool." << endl;
    cout << "Created by: Owen Sullivan, CPSC 1020-010." << endl;
    cout << "Note: This program's scope is limited to dates between 01/01/2021 and 12/31/2022." << endl;
    cout << endl;

    // Start by asking the user if they're positive for COVID-19
    char hasTestedPositive;
    cout << "Have you recently tested positive for COVID-19? (Y/N): ";
    cin >> hasTestedPositive;

    // Input validation for hasTestedPositive
    while (hasTestedPositive != 'y' && hasTestedPositive != 'Y' && hasTestedPositive != 'n' && hasTestedPositive != 'N') {
        cout << hasTestedPositive << " is not a valid response. Please enter Y for \"yes\" or N for \"no\": ";
        cin >> hasTestedPositive;
    }

    hasTestedPositive = toupper(hasTestedPositive); // Convert hasTestedPositive to uppercase for later logic

    // Determine course of action based on value of hasTestedPositive
    if (hasTestedPositive == 'Y') { // If yes
        // Keep local variables within scope of if statement
        int dayPositive;
        int monthPositive;
        int yearPositive;

        // Ask the user when they tested positive
        cout << "On what date did you test positive?" << endl;

        cout << "Month (1-12): ";
        cin >> monthPositive;
        
        cout << "Day: ";
        cin >> dayPositive;
        
        cout << "Year (2021-2022): ";
        cin >> yearPositive;
        
        Date datePositive(dayPositive, monthPositive, yearPositive); // Declare and construct datePositive object of type Date
        
        // Output results and end program (tested positive)
        cout << "Test result: positive" << endl;
        cout << "Date tested positive: " << datePositive.showDate() << endl;
        cout << "Length of isolation: 5 days" << endl;
        exit(0);
    } // If no, move on

    // Ask the user if they've been exposed
    char hasBeenExposed;
    cout << "Have you recently been exposed to someone who tested positive for COVID-19? (Y/N): ";
    cin >> hasBeenExposed;

    // Input validation for hasBeenExposed
    while (hasBeenExposed != 'y' && hasBeenExposed != 'Y' && hasBeenExposed != 'n' && hasBeenExposed != 'N') {
        cout << hasBeenExposed << " is not a valid response. Please enter Y for \"yes\" or N for \"no\": ";
        cin >> hasBeenExposed;
    }

    hasBeenExposed = toupper(hasBeenExposed); // Convert hasBeenExposed to uppercase for later logic

    // Determine course of action based on value of hasBeenExposed
    if (hasBeenExposed == 'N') { // If no
        // Output results and end program (not exposed)
        cout << "Test result: negative" << endl;
        cout << "Exposed to positive case: No" << endl;
        cout << "Length of isolation: 0 days" << endl;
        exit(0);
    } // If yes, move on

    int dayExposed;
    int monthExposed;
    int yearExposed;

    // Ask user when they were exposed
    cout << "On what date were you exposed?" << endl;

    cout << "Month (1-12): ";
    cin >> monthExposed;
        
    cout << "Day: ";
    cin >> dayExposed;
        
    cout << "Year (2021-2022): ";
    cin >> yearExposed;
        
    Date dateExposed(dayExposed, monthExposed, yearExposed); // Declare and construct dateExposed object of type Date

    // Ask user if they've received two doses of a vaccine
    char hasBeenVaccinated;
    cout << "Have you received two doses of a COVID-19 vaccine? (Y/N): ";
    cin >> hasBeenVaccinated;

    // Input validation for hasBeenVaccinated
    while (hasBeenVaccinated != 'y' && hasBeenVaccinated != 'Y' && hasBeenVaccinated != 'n' && hasBeenVaccinated != 'N') {
        cout << hasBeenVaccinated << " is not a valid response. Please enter Y for \"yes\" or N for \"no\": ";
        cin >> hasBeenVaccinated;
    }

    hasBeenVaccinated = toupper(hasBeenVaccinated); // Convert hasBeenVaccinated to uppercase for later logic

    // Determine course of action based on value of hasBeenVaccinated
    if (hasBeenVaccinated == 'N') { // If no
        // Output results and exit program (not vaccinated)
        cout << "Test result: negative" << endl;
        cout << "Exposed to positive case: Yes" << endl;
        cout << "Date exposed to positive case: " << dateExposed.showDate() << endl;
        cout << "Second vaccination does received: No" << endl;
        cout << "Vaccination status at time of exposure: not fully vaccinated" << endl;
        cout << "Length of isolation: 10 days" << endl;
        exit(0);
    } // If yes, move on

    int daySecondDose;
    int monthSecondDose;
    int yearSecondDose;

    // Ask user when they received their second dose
    cout << "On what date did you receive your second vaccine dose?" << endl;
    cout << "Month (1-12): ";
    cin >> monthSecondDose;
        
    cout << "Day: ";
    cin >> daySecondDose;
        
    cout << "Year (2021-2022): ";
    cin >> yearSecondDose;
        
    Date dateSecondDose(daySecondDose, monthSecondDose, yearSecondDose); // Declare and construct dateSecondDose object of type Date

    int numDaysBetween = calcDays(dateExposed, dateSecondDose); // Store the number of days between dateExposed and dateSecondDose

    // Determine course of action based on value of numDaysBetween
    if (numDaysBetween >= 14) { // If dates are 14 or more days apart
        // Output results (fully vaccinated)
        cout << "Test result: negative" << endl;
        cout << "Exposed to positive case: Yes" << endl;
        cout << "Date exposed to positive case: " << dateExposed.showDate() << endl;
        cout << "Second vaccination does received: Yes" << endl;
        cout << "Date second vaccination dose received: " << dateSecondDose.showDate() << endl;
        cout << "Vaccination status at time of exposure: fully vaccinated" << endl;
        cout << "Length of isolation: 5 days" << endl;
    } else {
        // Output results (not fully vaccinated)
        cout << "Test result: negative" << endl;
        cout << "Exposed to positive case: Yes" << endl;
        cout << "Date exposed to positive case: " << dateExposed.showDate() << endl;
        cout << "Second vaccination does received: Yes" << endl;
        cout << "Date second vaccination dose received: " << dateSecondDose.showDate() << endl;
        cout << "Vaccination status at time of exposure: not fully vaccinated" << endl;
        cout << "Length of isolation: 10 days" << endl;
    }

    return 0;

}