Compile function Operation_Services(@Service, @Params)
#pragma precomp SRP_PreCompiler

Declare function Database_Services, SRP_Json
Declare subroutine Database_Services, SRP_Json, Btree.Extract

$insert LOGICAL
$Insert OPERATION_EQUATES

Options OPERATION_TYPE = 'CLEAN', 'THICK_METROLOGY', 'RES_METROLOGY', 'SURFACE_METROLOGY', 'VISUAL_INSPECTION', 'PACKAGING'

GoToService

Return Response or ""

//-----------------------------------------------------------------------------
// SERVICES
//-----------------------------------------------------------------------------

Service ConvertRecordToJson(OperationId)
    
    JsonString   = ''
    objJSON = ''
    OperationRec = Database_Services('ReadDataRow', 'OPERATION', OperationId, True$, 0, False$)
    If SRP_JSON(objJSON, 'New', 'Object') then
        SRP_JSON(objJSON, 'SetValue', 'OperationId', OperationId)
        SRP_JSON(objJSON, 'SetValue', 'Active', OperationRec<OPERATION_ACTIVE$>, 'Boolean')
        SRP_JSON(objJSON, 'SetValue', 'ClassId', OperationRec<OPERATION_CLASS_ID$>, 'String')
        SRP_JSON(objJSON, 'SetValue', 'Description', OperationRec<OPERATION_OPERATION_DESCRIPTION$>, 'String')
        SRP_JSON(objJSON, 'SetValue', 'Type', OperationRec<OPERATION_TYPE$>, 'String')
        JsonString = SRP_JSON(objJSON, 'Stringify', 'Styled')
        SRP_JSON(objJSON, 'Release')
    end
    
    Response = JsonString
    
End Service

Service GetOperations(Class, ActiveFlag)
    
    ErrorMessage = ''
    RTFOperationKeys = ''
    
    Open 'DICT.OPERATION' to DICT then
        SearchString = 'CLASS_ID':@VM:Class:@FM
        SearchString := 'ACTIVE':@VM:True$:@FM
        Option = ''
        Flag = ''
        Btree.Extract(SearchString, 'OPERATION', DICT, RTFOperationKeys, Option, Flag)
    end else
        ErrorMessage = 'Error opening OPERATION table dictionary.'
    end
    
    Response = RTFOperationKeys
    
end service

