#ifndef ROOMAPI_H
#define ROOMAPI_H

#include "network/networkaccessmanager.h"
#include "qjsonarray.h"

#include <QMetaType>
#include <QString>
#include <QStringList>

#include <optional>

class RoomInfo
{
    Q_GADGET
    Q_PROPERTY(std::optional<QString> id MEMBER id)
    Q_PROPERTY(std::optional<QString> name MEMBER name)
    Q_PROPERTY(std::optional<QString> description MEMBER description)
    Q_PROPERTY(std::optional<int> maxUsers MEMBER maxUsers)
    Q_PROPERTY(std::optional<int> status MEMBER status)
    Q_PROPERTY(std::optional<int> liveStatus MEMBER liveStatus)
    Q_PROPERTY(std::optional<qint64> createdAt MEMBER createdAt)
    Q_PROPERTY(std::optional<qint64> updatedAt MEMBER updatedAt)
    Q_PROPERTY(std::optional<QString> createdId MEMBER createdId)
    Q_PROPERTY(std::optional<QString> ownerId MEMBER ownerId)
public:
    RoomInfo() = default;

    std::optional<QString> id;          // 房间当前id
    std::optional<QString> name;        // 房间名
    std::optional<QString> description; // 房间的描述信息
    std::optional<int> maxUsers;        // 最大用户数
    std::optional<int> status;          // 1: normal 2: ban | 状态 1 正常 2 禁用
    std::optional<int> liveStatus;      // 直播状态 状态 0 未使用 1 在线 2 不在线
    std::optional<qint64> createdAt;    // 创建日期
    std::optional<qint64> updatedAt;    // 修改日期
    std::optional<QString> createdId;   // 创建者
    std::optional<QString> ownerId;     // 房主ID，关联用户表

    friend bool operator==(const RoomInfo &lhs, const RoomInfo &rhs)
    {
        return lhs.id == rhs.id && lhs.name == rhs.name && lhs.description == rhs.description
               && lhs.maxUsers == rhs.maxUsers && lhs.status == rhs.status
               && lhs.liveStatus == rhs.liveStatus && lhs.createdAt == rhs.createdAt
               && lhs.updatedAt == rhs.updatedAt && lhs.createdId == rhs.createdId
               && lhs.ownerId == rhs.ownerId;
    }
};
Q_DECLARE_METATYPE(RoomInfo)

class RoomListData
{
    Q_GADGET
    Q_PROPERTY(qint64 total MEMBER total)
    Q_PROPERTY(QList<RoomInfo> data MEMBER data)

public:
    RoomListData() {}
    RoomListData(const QJsonObject &object);

    RoomListData(const RoomListData &other) = default;
    RoomListData &operator=(const RoomListData &other) = default;

    QList<RoomInfo> getRooms() const;

private:
    qint64 total = 0;
    QList<RoomInfo> data;
};
Q_DECLARE_METATYPE(RoomListData)

QFuture<HttpResponse> getRoomListApi(const RoomInfo &roomInfo = RoomInfo(),
                                     int page = 1,
                                     int pageSize = 100);

QFuture<HttpResponse> getRoomApi(const QString &id);

#endif // ROOMAPI_H
