#include "information.h"


Information::Information()
{

}

QVector<Card*> *Information::getCards()
{
    return cards;
}

void Information::setCards(QVector<Card*> *value)
{
    cards = value;
}

void Information::createCards()
{
    cards = new QVector<Card*>;
    for (int i = 0; i < numberOfElements; i++)
    {
        cards->append(new Card());
    }
}

void Information::addProperty(int card, QString property, QString value)
{
    cards->at(card)->addProperty(property, value);
}

void Information::addProperty(int card, int propertyIndex, QString property, QString value)
{
    cards->at(card)->editProperty(propertyIndex, property, value);
}

void Information::removeProperty(int card, int indexProperty)
{
    cards->at(card)->removeProperty(indexProperty);
}

int Information::hasMaximumOfProoperties(int card)
{
    return cards->at(card)->getNumberOfProperties() >= (cardCols*cardRows);
}

int Information::getNumberOfProperties(int card)
{
    return cards->at(card)->getNumberOfProperties();
}

void Information::setCardTitle(int card, QString title)
{
    cards->at(card)->setTitle(title);
}

QString Information::getCardImage(int card)
{
    return cards->at(card)->getIconImage();
}

QString Information::getCardTitle(int card)
{
    return cards->at(card)->getTitle();
}

void Information::setCardImage(int card, QString path)
{
    cards->at(card)->setIconImage(path);
}

QStringList Information::takeProperty(int card, int indexProperty)
{
   return cards->at(card)->takeProperty(indexProperty);
}

QStringList Information::getProperty(int card, int indexProperty)
{
    return cards->at(card)->getProperty(indexProperty);
}

int Information::getCardCols()
{
    return cardCols;
}

void Information::setCardCols(int value)
{
    cardCols = value;
}

int Information::getCardRows()
{
    return cardRows;
}

void Information::setCardRows(int value)
{
    cardRows = value;
}

void Information::addEmptyLeftProperties(int card)
{
    Card *currentcard = cards->at(card);
    int addedProperties = currentcard->getNumberOfProperties();
    int totalProperties = getCardRows() * getCardCols();
    for(int i = addedProperties; i<totalProperties; i++)
        addProperty(card, QString(""), QString(""));
}

void Information::resizeNumberOfCards()
{
    int previousSize = cards->size();
    for(int i =0; i < abs(numberOfElements - previousSize); i++)
    {
        if(numberOfElements < previousSize)
        {
            cards->removeAt(cards->size() -1);
        }
        else
        {
            cards->append(new Card());
        }
    }
}

void Information::resizeNumberOfProperties()
{
    int numberOfProperties = getCardCols() * getCardRows();

    for(int cardNum = 0; cardNum < cards->size(); cardNum ++) {
        int previousValue = cards->at(cardNum)->getNumberOfProperties();
        if(previousValue > numberOfProperties)
        {
            for(int i = 0; i < previousValue - numberOfProperties; i++)
            {
                cards->at(cardNum)->takeProperty(cards->at(cardNum)->getNumberOfProperties() -1);
            }
        }
    }
}
