// Include statements
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>

// Include custom headers
#include "Date.h"

// Declare std namespace
using namespace std;

const string Date::MONTHS[12] {"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"}; // Initialize static string array with months of the year

void Date::setMonth(int m) { // Setter function for member variable month

    month = m;

}

void Date::setDay(int d) { // Setter function for member variable day

    day = d;

}

void Date::setYear(int y) { // Setter function for member variable year

    year = y;

}

int Date::getMonth() const { // Getter function for member variable month

    return month;

}

int Date::getDay() const { // Getter function for member variable day

    return day;

}

int Date::getYear() const { // Getter function for member variable year

    return year;

}

string Date::print() { // Function to assemble a string with formatted month (text form), day, and year of object

    // Declare stringstream variables
    stringstream month;
    stringstream day;
    stringstream year;

    month << left << setw(10) << MONTHS[this->getMonth() - 1]; // Generate stringstream justified left, with width 10, with contents of month specified
    day << left << setw(3) << this->getDay(); // Generate stringstream justified left, with width 3, with contents of day
    year << left << setw(5) << this->getYear(); // Generate stringstream justified left, with width 5, with contents of year

    string assembledString = month.str() + day.str() + year.str(); // Declare and initialize assembledString as a combination of existing stringstreams

    return assembledString; // Return assembledString

}

bool Date::compare(const Date &d1, const Date &d2) { // Function to compare two date objects for use in sort()

    if (d1.getYear() > d2.getYear()) { // If year 1 is greater than year 2
        return true;
    } else if (d1.getYear() < d2.getYear()) { // If year 1 is less than year 2
        return false;
    } else {
        if (d1.getMonth() > d2.getMonth()) { // If month 1 is greater than month 2
            return true;
        } else if (d1.getMonth() < d2.getMonth()) { // If month 1 is less than month 2
            return false;
        } else {
            if (d1.getDay() > d2.getDay()) { // If day 1 is greater than day 2
                return true;
            } else if (d1.getDay() < d2.getDay()) { // If day 1 is less than day 2
                return false;
            } else { // If day 1 and day 2 are equal
                return false; // Return false because one is not larger than the other
            }
        }
    }

}