1190978c3Sopenharmony_ci/*
2190978c3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3190978c3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4190978c3Sopenharmony_ci * you may not use this file except in compliance with the License.
5190978c3Sopenharmony_ci * You may obtain a copy of the License at
6190978c3Sopenharmony_ci *
7190978c3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8190978c3Sopenharmony_ci *
9190978c3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10190978c3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11190978c3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12190978c3Sopenharmony_ci * See the License for the specific language governing permissions and
13190978c3Sopenharmony_ci * limitations under the License.
14190978c3Sopenharmony_ci */
15190978c3Sopenharmony_ci
16190978c3Sopenharmony_ci#ifndef UPDATE_SERVICE_ERROR_MESSAGE_H
17190978c3Sopenharmony_ci#define UPDATE_SERVICE_ERROR_MESSAGE_H
18190978c3Sopenharmony_ci
19190978c3Sopenharmony_ci#include <cstdint>
20190978c3Sopenharmony_ci#include <string>
21190978c3Sopenharmony_ci
22190978c3Sopenharmony_ci#include "nlohmann/json.hpp"
23190978c3Sopenharmony_ci
24190978c3Sopenharmony_ci#include "dupdate_json_utils.h"
25190978c3Sopenharmony_ci#include "json_builder.h"
26190978c3Sopenharmony_ci
27190978c3Sopenharmony_cinamespace OHOS::UpdateEngine {
28190978c3Sopenharmony_cistruct ErrorMessage {
29190978c3Sopenharmony_ci    int32_t errorCode = 0;
30190978c3Sopenharmony_ci    std::string errorMessage;
31190978c3Sopenharmony_ci
32190978c3Sopenharmony_ci    friend void to_json(nlohmann::json &jsonObj, const ErrorMessage &message)
33190978c3Sopenharmony_ci    {
34190978c3Sopenharmony_ci        jsonObj["errorCode"] = message.errorCode;
35190978c3Sopenharmony_ci        jsonObj["errorMessage"] = message.errorMessage;
36190978c3Sopenharmony_ci    }
37190978c3Sopenharmony_ci
38190978c3Sopenharmony_ci    friend void from_json(const nlohmann::json &jsonObj, ErrorMessage &message)
39190978c3Sopenharmony_ci    {
40190978c3Sopenharmony_ci        JsonUtils::GetValueAndSetTo(jsonObj, "errorCode", message.errorCode);
41190978c3Sopenharmony_ci        JsonUtils::GetValueAndSetTo(jsonObj, "errorMessage", message.errorMessage);
42190978c3Sopenharmony_ci    }
43190978c3Sopenharmony_ci
44190978c3Sopenharmony_ci    JsonBuilder GetJsonBuilder()
45190978c3Sopenharmony_ci    {
46190978c3Sopenharmony_ci        return JsonBuilder()
47190978c3Sopenharmony_ci            .Append("{")
48190978c3Sopenharmony_ci            .Append("errorCode", errorCode)
49190978c3Sopenharmony_ci            .Append("errorMessage", errorMessage)
50190978c3Sopenharmony_ci            .Append("}");
51190978c3Sopenharmony_ci    }
52190978c3Sopenharmony_ci};
53190978c3Sopenharmony_ci} // namespace OHOS::UpdateEngine
54190978c3Sopenharmony_ci#endif // UPDATE_SERVICE_ERROR_MESSAGE_H
55