Function Equipmentstatuses_API(@API)
/***********************************************************************************************************************

    This program is proprietary and is not to be used by or disclosed to others, nor is it to be copied without written
    permission from SRP Computer Solutions, Inc.

    Name        :   Equipmentstatuses_API

    Description :   API logic for the Equipmentstatuses resource.

    Notes       :   All web APIs should include the API_SETUP insert. This will provide several useful variables:

                        HTTPMethod              - The HTTP Method (Verb) submitted by the client (e.g., GET, POST, etc.)
                        APIURL                  - The URL for the API entry point (e.g., api.mysite.com/v1).
                        FullEndpointURL         - The URL submitted by the client, including query params.
                        FullEndpointURLNoQuery  - The URL submitted by the client, excluding query params.
                        EndpointSegment         - The URL endpoint segment.
                        ParentURL               - The URL path preceeding the current endpoint.
                        CurrentAPI              - The name of this stored procedure.

    Parameters  :
        API             [in] -- Web API to process. Format is [APIPattern].[HTTPMethod]:
                                    - APIPattern must follow this structure Equipmentstatuses[.ID.[<Property>]]
                                    - HTTPMethod can be any valid HTTP method, e.g., GET, POST, PUT, DELETE, etc.
                                Examples:
                                    - Equipmentstatuses.POST
                                    - Equipmentstatuses.ID.PUT
                                    - Equipmentstatuses.ID.firstName.GET
        Response       [out] -- Response to be sent back to the Controller (HTTP_MCP) or requesting procedure. Web API
                                services do not rely upon anything being returned in the response. This is what the
                                various services like SetResponseBody and SetResponseStatus services are for. A response
                                value is only helpful if the developers want to use it for debug purposes.

    History     :   (Date, Initials, Notes)
        06/28/22    xxx     Original programmer.

***********************************************************************************************************************/

#pragma precomp SRP_PreCompiler

Declare function Reactor_Services

$insert APP_INSERTS
$insert API_SETUP
$insert HTTP_INSERTS

GoToAPI else
    // The specific resource endpoint doesn't have a API handler yet.
    HTTP_Services('SetResponseStatus', 204, 'This is a valid endpoint but a web API handler has not yet been created.')
end

Return Response OR ''


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Endpoint Handlers
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


API equipmentstatuses.HEAD
API equipmentstatuses.GET

    equipType     = HTTP_Services('GetQueryField', 'EquipType')
    equipId       = HTTP_Services('GetQueryField', 'EquipId')
    ResultingJSON = ''
    Begin Case
        Case equipType EQ 'nonReactor'
            null
        Case equipType EQ 'Reactor'
            If equipId EQ '' then
                //All Reactors
                ResultingJSON = Reactor_Services('GetAllReactStatusJson')
                StatusCode    = 201
            end else
                //single reactor
                ResultingJSON = Reactor_Services('GetSingleReactStatusJson', equipId)
                StatusCode    = 201
            end
        Case 1
            ResultingJSON = Reactor_Services('GetAllReactStatusJson')
            StatusCode    = 201
    End Case
            HTTP_Services('SetResponseHeaderField', 'Content-Location', FullEndpointURL)
        HTTP_Services('SetResponseBody', ResultingJSON, False$, 'application/json')
        If Assigned(Message) then
            HTTP_Services('SetResponseStatus', StatusCode, Message)
        end else
            HTTP_Services('SetResponseStatus', StatusCode)
        end
    

end api

//----------------------------------------------------------------------------------------------------------------------
// CreateHALItem
//
// Creates a HAL+JSON object based on the OpenInsight data row representation of the scan.
//----------------------------------------------------------------------------------------------------------------------
CreateHALItem:
    
    //TransactionJSON = OI_Wizard_Services('ConvertMVTransactionToJSON', TransactionID, '', FullEndpointURL)

    If SRP_Json(objJsonHAL, "New") then
        if SRP_Json(objExistingJSON, "New", "Object") then
            SRP_Json(objExistingJSON, 'SetValue', 'data', ResultingJSON, 'String')
            
        SRP_JSON(objJsonHAL, 'Set', 'Data', objExistingJSON)
        SRP_Json(objExistingJSON, "Release")
        end 
    
        If SRP_JSON(objLinks, 'New', 'Object') then
                        // Create a self link.
                        If SRP_JSON(objLink, 'New', 'Object') then
                            SRP_JSON(objLink, 'SetValue', 'href', FullEndpointURL, 'String')
                            SRP_JSON(objLink, 'SetValue', 'title', 'Self', 'String')
                            SRP_JSON(objLinks, 'Set', 'self', objLink)
                            SRP_JSON(objLink, 'Release')
                        end
                        SRP_JSON(objJsonHAL, 'Set', '_links', objLinks)
                        SRP_JSON(objLinks, 'Release')
                    end

                    // Create the _form property to help UIs determine what to display.
                    If SRP_JSON(objForm, 'New', 'Object') then
                        If SRP_JSON(arrayFields, 'New', 'Array') then
                            If SRP_JSON(objField, 'New', 'Object') then
                                SRP_JSON(objField, 'SetValue', 'label', 'Example Label', 'String')
                                SRP_JSON(objField, 'SetValue', 'value', 'Example Value', 'String')
                                SRP_JSON(arrayFields, 'Add', objField)
                                SRP_JSON(objField, 'Release')
                            end
                            SRP_JSON(objForm, 'Set', 'fields', arrayFields)
                            SRP_JSON(arrayFields, 'Release')
                        end
                        SRP_JSON(objJsonHAL, 'Set', '_form', objForm)
                        SRP_JSON(objForm, 'Release')
                    end
                    // Create the _class property for this resource.
                    SRP_JSON(objJsonHAL, 'SetValue', '_class', 'resource')
                end
                jsonTransaction    = SRP_JSON(objJsonHAL, 'Stringify', 'Styled')
   // Remember to release entities you've created
   
   SRP_Json(objJsonHAL, "Release")
 


* 
*    If Error_Services('NoError') then
      

*    end else
*        Message = Error_Services('GetMessage')          
*        HTTP_Services('SetResponseStatus', 500, 'Error in the ' : CurrentAPI : ' API. Message: ': Message)
*    end

return
