12973963eSXiaochao Ma #pragma once
22973963eSXiaochao Ma 
32973963eSXiaochao Ma #include "app.hpp"
4ce05f6c4SNan Zhou #include "logging.hpp"
52973963eSXiaochao Ma #include "query.hpp"
62973963eSXiaochao Ma #include "registries/privilege_registry.hpp"
72973963eSXiaochao Ma #include "utils/chassis_utils.hpp"
82973963eSXiaochao Ma #include "utils/json_utils.hpp"
92973963eSXiaochao Ma 
10ef4c65b7SEd Tanous #include <boost/url/format.hpp>
11ef4c65b7SEd Tanous 
12ce05f6c4SNan Zhou #include <optional>
13ce05f6c4SNan Zhou #include <string>
14ce05f6c4SNan Zhou 
152973963eSXiaochao Ma namespace redfish
162973963eSXiaochao Ma {
172973963eSXiaochao Ma 
182973963eSXiaochao Ma inline void doThermalSubsystemCollection(
192973963eSXiaochao Ma     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
202973963eSXiaochao Ma     const std::string& chassisId,
212973963eSXiaochao Ma     const std::optional<std::string>& validChassisPath)
222973963eSXiaochao Ma {
232973963eSXiaochao Ma     if (!validChassisPath)
242973963eSXiaochao Ma     {
25*62598e31SEd Tanous         BMCWEB_LOG_WARNING("Not a valid chassis ID{}", chassisId);
262973963eSXiaochao Ma         messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
272973963eSXiaochao Ma         return;
282973963eSXiaochao Ma     }
291aee751cSGeorge Liu 
301aee751cSGeorge Liu     asyncResp->res.addHeader(
311aee751cSGeorge Liu         boost::beast::http::field::link,
321aee751cSGeorge Liu         "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
332973963eSXiaochao Ma     asyncResp->res.jsonValue["@odata.type"] =
342973963eSXiaochao Ma         "#ThermalSubsystem.v1_0_0.ThermalSubsystem";
352973963eSXiaochao Ma     asyncResp->res.jsonValue["Name"] = "Thermal Subsystem";
362973963eSXiaochao Ma     asyncResp->res.jsonValue["Id"] = "ThermalSubsystem";
372973963eSXiaochao Ma 
38ef4c65b7SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
39ef4c65b7SEd Tanous         "/redfish/v1/Chassis/{}/ThermalSubsystem", chassisId);
402973963eSXiaochao Ma 
419516f41fSGeorge Liu     asyncResp->res.jsonValue["Fans"]["@odata.id"] = boost::urls::format(
429516f41fSGeorge Liu         "/redfish/v1/Chassis/{}/ThermalSubsystem/Fans", chassisId);
439516f41fSGeorge Liu 
442973963eSXiaochao Ma     asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
452973963eSXiaochao Ma     asyncResp->res.jsonValue["Status"]["Health"] = "OK";
462973963eSXiaochao Ma }
472973963eSXiaochao Ma 
481aee751cSGeorge Liu inline void handleThermalSubsystemCollectionHead(
492973963eSXiaochao Ma     App& app, const crow::Request& req,
502973963eSXiaochao Ma     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
511aee751cSGeorge Liu     const std::string& chassisId)
522973963eSXiaochao Ma {
532973963eSXiaochao Ma     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
542973963eSXiaochao Ma     {
552973963eSXiaochao Ma         return;
562973963eSXiaochao Ma     }
571aee751cSGeorge Liu 
581aee751cSGeorge Liu     auto respHandler = [asyncResp, chassisId](
591aee751cSGeorge Liu                            const std::optional<std::string>& validChassisPath) {
601aee751cSGeorge Liu         if (!validChassisPath)
611aee751cSGeorge Liu         {
621aee751cSGeorge Liu             messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
631aee751cSGeorge Liu             return;
641aee751cSGeorge Liu         }
651aee751cSGeorge Liu         asyncResp->res.addHeader(
661aee751cSGeorge Liu             boost::beast::http::field::link,
671aee751cSGeorge Liu             "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby");
681aee751cSGeorge Liu     };
691aee751cSGeorge Liu     redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId,
701aee751cSGeorge Liu                                                 std::bind_front(respHandler));
711aee751cSGeorge Liu }
721aee751cSGeorge Liu 
731aee751cSGeorge Liu inline void handleThermalSubsystemCollectionGet(
741aee751cSGeorge Liu     App& app, const crow::Request& req,
751aee751cSGeorge Liu     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
761aee751cSGeorge Liu     const std::string& chassisId)
771aee751cSGeorge Liu {
781aee751cSGeorge Liu     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
791aee751cSGeorge Liu     {
801aee751cSGeorge Liu         return;
811aee751cSGeorge Liu     }
822973963eSXiaochao Ma 
832973963eSXiaochao Ma     redfish::chassis_utils::getValidChassisPath(
842973963eSXiaochao Ma         asyncResp, chassisId,
852973963eSXiaochao Ma         std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId));
862973963eSXiaochao Ma }
872973963eSXiaochao Ma 
882973963eSXiaochao Ma inline void requestRoutesThermalSubsystem(App& app)
892973963eSXiaochao Ma {
902973963eSXiaochao Ma     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
911aee751cSGeorge Liu         .privileges(redfish::privileges::headThermalSubsystem)
921aee751cSGeorge Liu         .methods(boost::beast::http::verb::head)(std::bind_front(
931aee751cSGeorge Liu             handleThermalSubsystemCollectionHead, std::ref(app)));
941aee751cSGeorge Liu 
951aee751cSGeorge Liu     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/")
962973963eSXiaochao Ma         .privileges(redfish::privileges::getThermalSubsystem)
972973963eSXiaochao Ma         .methods(boost::beast::http::verb::get)(std::bind_front(
982973963eSXiaochao Ma             handleThermalSubsystemCollectionGet, std::ref(app)));
992973963eSXiaochao Ma }
1002973963eSXiaochao Ma 
1012973963eSXiaochao Ma } // namespace redfish
102