#include "InteractiveData.h"

InteractiveData::InteractiveData()
{
    // 物资类型
    m_modelMaterialType.addRole("materialsTypeId");
    m_modelMaterialType.addRole("materialsTypeName");
    m_modelMaterialType.addRole("materialsTypeIcon");
    m_modelMaterialType.addRole("materialsTypeError");
    m_modelMaterialType.addRole("materialsTypePicture");
    m_modelMaterialType.addRole("materialsTypeSelected");


    // 物资信息
    m_modelMaterialInfo.addRole("materialsId");
    m_modelMaterialInfo.addRole("materialsName");
    m_modelMaterialInfo.addRole("materialsRfid");
    m_modelMaterialInfo.addRole("expirationDate");
    m_modelMaterialInfo.addRole("status");
    m_modelMaterialInfo.addRole("materialsTypePicture");


    // 手动更换
    m_modelMaterialManualReplace.addRole("oldMaterialsId");
    m_modelMaterialManualReplace.addRole("oldMaterialsId");
    m_modelMaterialManualReplace.addRole("materialsName");
    m_modelMaterialManualReplace.addRole("materialsRfid");
    m_modelMaterialManualReplace.addRole("expirationDate");
    m_modelMaterialManualReplace.addRole("propertiesValue");
    m_modelMaterialManualReplace.addRole("materialsTypeName");
    m_modelMaterialManualReplace.addRole("materialsTypePicture");

    m_modelMaterialManualReplace.addRole("oldMaterialsName");
    m_modelMaterialManualReplace.addRole("oldMaterialsRfid");
    m_modelMaterialManualReplace.addRole("oldExpirationDate");
    m_modelMaterialManualReplace.addRole("oldPropertiesValue");
    m_modelMaterialManualReplace.addRole("oldMaterialsTypeName");
    m_modelMaterialManualReplace.addRole("oldMaterialsTypePicture");

    m_modelMaterialManualReplace.addRole("status");
    m_modelMaterialManualReplace.addRole("types");
    m_modelMaterialManualReplace.addRole("click");

    // 异常上报
    m_modelMaterialException.addRole("materialsId");
    m_modelMaterialException.addRole("materialsName");
    m_modelMaterialException.addRole("materialsRfid");
    m_modelMaterialException.addRole("expirationDate");
    m_modelMaterialException.addRole("status");
    m_modelMaterialException.addRole("materialsTypePicture");
}

bool InteractiveData::isHavePower(const QString &operation)
{
    // 物资领取归还 iscs:receive-return
    // 物资使用说明 iscs:Instructions
    // 物资检查计划 iscs:Inspection-plan
    // 物资更换 iscs:replacement
    // 异常处理 iscs:exception

    // 如果角色包含超级管理员
    if (m_roles.contains(QString("admin")))
    {
        return true;
    }
    // 如果是其他用户，判断是否有执行该操作的权利
    else if (m_permissions.contains(operation))
    {
        return true;
    }
    // 如果没有权利执行该操作
    else
    {
        return false;
    }
}

QSet<QString> InteractiveData::roles()
{
    return m_roles;
}

void InteractiveData::setRoles(const QSet<QString> &roles)
{
    m_roles = roles;
    emit rolesChanged();
}

QSet<QString> InteractiveData::permissions()
{
    return m_permissions;
}

void InteractiveData::setPermissions(const QSet<QString> &permissions)
{
    m_permissions = permissions;
    emit permissionsChanged();
}

