#ifndef STUDENTSERVICE_H
#define STUDENTSERVICE_H
#include <QObject>
#include <QSortFilterProxyModel>
#include "core/student.h"
#include "data/dataStorage.h"
class StudentService : public QObject
{
Q_OBJECT
Q_PROPERTY(QVariantList students READ students NOTIFY studentsChanged)
public:
explicit StudentService(DataStorage *storage, QObject *parent = nullptr);
Q_INVOKABLE void addStudent(Student *student);
Q_INVOKABLE void updateStudent(const QString &id, Student *newInfo);
Q_INVOKABLE void deleteStudent(const QString &id);
Q_INVOKABLE Student *getStudentById(const QString &id);
Q_INVOKABLE QVariantList getCollegeStats() const;
Q_INVOKABLE QVariantList getHometownStats() const;
Q_INVOKABLE void sortStudents(const QString &field);
Q_INVOKABLE QList<Student *> searchStudents(const QString &field, const QString &value);
Q_INVOKABLE QVariantMap countStatistics();
Q_INVOKABLE QVariantList students() const;
Q_INVOKABLE QList<Student*> loadStudents();
int totalStudents() const { return m_totalStudents; }
int collegeCount() const { return m_collegeCount; }
int classCount() const { return m_classCount; }
int maleCount() const { return m_maleCount; }
int femaleCount() const { return m_femaleCount; }
void calculateStatistics();
signals:
void studentsChanged();
void statsUpdated();
private:
DataStorage *m_storage;
QList<Student *> m_students;
int m_totalStudents = 0;
int m_collegeCount = 0;
int m_classCount = 0;
int m_maleCount = 0;
int m_femaleCount = 0;
};
#endif