// @topic W15-2-030 pet license application v3
// @brief main driver program

#include <iostream>
#include <cstdlib>
#include <ctime>

#include "pet_license.h"

int main()
{
    // init pseudo-random number generator
    srand( int( time( nullptr ) ) );

    // ask the user to enter the data;
    std::string name;
    int age = 0;
    std::string address;

    while ( true ) {
        int answer;
        std::cout << "Enter 1 to continue, or 0 to exit: ";
        std::cin >> answer;
        if ( answer == 0 ) {
            break;
        }

        // get rid of newline in input which is a leftover from
        // getting 0 or 1 above
        getline( std::cin, name );

        std::cout << "Pet owner name: ";
        getline( std::cin, name );

        std::cout << " Pet owner age: ";
        std::cin >> age;

        // get rid of newline leftover in input
        getline( std::cin, address );

        std::cout << "Pet owner address: ";
        getline( std::cin, address );

        // create the owner object
        PetOwner owner( name, age, address );

        // Populate collection of pets
        int number_of_pets;
        std::cout << "How many pets do you have? : ";
        std::cin >> number_of_pets;

        std::string name;
        char type;
        int age;
        std::string color;
        bool adoption;

        while ( number_of_pets-- ) {
            // get rid of newline leftover in input
            getline( std::cin, name );

            std::cout << "Pet name: ";
            getline( std::cin, name );

            std::cout << "Enter C for a cat or D for a dog: ";
            std::cin >> type;

            std::cout << " Pet age in years: ";
            std::cin >> age;

            // get rid of newline leftover in input
            getline( std::cin, color );

            std::cout << "Pet color: ";
            getline( std::cin, color );

            std::cout << "Is this an adoption: Y/N ";
            char answer;
            std::cin >> answer;
            adoption = ( answer == 'Y' );
            owner.add( create_pet( type, name, age, color, adoption ) );

            std::cout << name << " added successfully\n";
        }//while

        // Create a license
        PetLicense license( &owner );
        license.calculate_fee();
        license.print();

    }// while

    system( "pause" );
    return 0;
}
