summaryrefslogtreecommitdiff
path: root/src/model/MedalWinner.h
blob: e771185d6e7114abd45165a520ed940bf970447d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

#ifndef ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H
#define ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H

#include "Competitor.h"
#include <QMap>
#include <QJsonObject>
#include <stdexcept>

class MedalWinner : public Competitor {

public:
    MedalWinner(const MedalWinner &medalWinner) : Competitor(medalWinner) {
        this->wonMedals = {
                {QString("ME_GOLD"), medalWinner.wonMedals.value("ME_GOLD")},
                {QString("ME_SILVER"), medalWinner.wonMedals.value("ME_SILVER")},
                {QString("ME_BRONZE"), medalWinner.wonMedals.value("ME_BRONZE")}
        };
    }

    MedalWinner(const QJsonObject &competitor) : Competitor(competitor) {
        if (competitor.contains("medals")) throw invalid_argument("Competitor has no medals.");
        QJsonObject medals = competitor["medals"].toObject();
        setMedals(medals);
    }

    bool setMedals(const QJsonObject &medals);

private:
    QMap<QString, QString> wonMedals;

};


#endif //ITAT_CHALLANGE_OLYMPICS_MEDALWINNER_H