// @topic W11-2-020 pet license application
// @brief C++ classes implementation

#include "pet_license.h"

Pet::Pet(
    std::string name,
    char type,
    int age,
    std::string color,
    bool adoption
    )
    : // initializer list
    name( name ),
    type( type ),
    age( age ),
    color( color ),
    adoption( adoption )
{
}//Pet::Pet()


PetOwner::PetOwner(
    std::string name,
    int age,
    std::string address
    )
    : // initializer list
    name( name ),
    age( age ),
    address( address )
{
}//PetOwner::PetOwner()


void PetOwner::add( Pet const& ref_pet )
{
    pets.push_back( ref_pet );
}//PetOwner::add()


void PetOwner::print()
{
    std::cout << "Name: " << name << "\n";
    std::cout
        << "Senior Citizen: "
        << ( is_senior_citizen() ? 'Y' : 'N' )
        << "\n"
        ;
    std::cout << "Address: " << address << "\n";
    for ( Pet& pet : pets ) {
        // C++2011
        pet.print();
    }
}//PetOwner::print()


bool PetOwner::is_senior_citizen()
{
    return ( age >= SENIOR_CITIZEN_AGE );
}//PetOwner::is_senior_citizen()


void Pet::print()
{
    std::cout << ( type == 'C' ? "Cat" : "Dog" );
    std::cout << ": " << name;
    std::cout << " age " << age;
    std::cout << ( adoption ? " (adoption)" : "" ) << "\n";
}//Pet::print()


PetLicense::PetLicense( PetOwner* powner )
    :
    powner( powner ),
    total_fee( 0.00 ),
    license_number( rand() % 10000 + 10000 )
{
}//PetLicense::PetLicense()


double PetLicense::calculate_fee()
{
    total_fee += license_fee;
    total_fee += state_fee;
    if ( powner->is_senior_citizen() ) {
        total_fee -= discount_fee;
    }
    // Rules:
    // 1). One processing fee per dog
    // 2). One processing fee per three cats
    int cat_count = 0;
    bool cat_adoption = false;
    for ( Pet & pet : powner->pets ) {
        //total_fee += pet.calculate_fee();
        if ( pet.type == 'D' ) {
            total_fee += processing_fee;
            if ( pet.adoption ) {
                total_fee -= discount_fee;
            }
        } else {
            ++cat_count;
            if ( pet.adoption ) cat_adoption = true;
            if ( cat_count >= cats_per_license ) {
                total_fee += processing_fee;
                if ( cat_adoption ) {
                    total_fee -= discount_fee;
                }
                // reset indicators for a group of cats
                cat_count = 0;
                cat_adoption = false;
            }
        }
    }//for
    return 0.0;
}//PetLicense::calculate_fee()


void PetLicense::print()
{
    std::cout << "---------------------------------------\n";
    std::cout << "PET LICENSE #" << license_number << "\n";
    powner->print();
    std::cout << "\nTotal license fee charge: " << total_fee << "\n";
    std::cout << "---------------------------------------\n";
}//PetLicense::print()
    