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

Declare function Database_Services, SRP_JSON
Declare Subroutine Btree.Extract, SRP_JSON, Error_Services, Rlist

$insert LOGICAL
$insert TEST_WAFER_PROD_EQUATES

GoToService

Return Response or ""

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

Service GetAllTestWaferProdIDs(ShowSorted)
    keylist  = ''
    ProdList = ''
    If ShowSorted then
        RList("SELECT TEST_WAFER_PROD WITH SORT_ORDER NE 0 AND WITH SORT_ORDER NE '' BY SORT_ORDER", 5, '', '', '')
    end else
        RList("SELECT TEST_WAFER_PROD BY SORT_ORDER", 5, '', '', '')
    end
    Done     = False$
    Loop
        Readnext TWProdKey else Done = True$
    Until Done
        keylist<-1> = TWProdKey
    Repeat
    Response = keylist
end service

Service GetTestWaferProdIDsByPartName(PartName)
    TWPartIDs = ''
    OPEN 'DICT.TEST_WAFER_PROD' TO DictVar THEN
        SearchString = 'PART_NAME':@VM:PartName:@FM
        Flag         = ''
        Btree.Extract(SearchString, 'TEST_WAFER_PROD', DictVar, TWPartIDs, '', Flag)
    end else
        Error_Services('Add', 'Error opening TEST_WAFER_PROD dictionary')
    end
    Response = TWPartIDs  
    
End Service

Service ConvertRecordToJson(TWProdId)
    JSON      = ''
    TWProdRec = Database_Services('ReadDataRow', 'TEST_WAFER_PROD', TWProdId)
    If SRP_JSON(hJSONCollection, 'New', 'Object') then
        hTWProdObj = ''
        If SRP_Json(hTWProdObj, 'New', 'Object') then
            SRP_JSON(hTWProdObj, 'SetValue', 'TestWaferProdId', TWProdId)
            SRP_JSON(hTWProdObj, 'SetValue', 'TestWaferPartName', TWProdRec<TEST_WAFER_PROD_PART_NAME$>)
            SRP_JSON(hJSONCollection, 'Set', 'TEST_WAFER_PROD', hTWProdObj)
            SRP_JSON(hTWProdObj, 'Release')
        end
        JSON = SRP_JSON(hJSONCollection, 'Stringify', 'Styled')
       SRP_JSON(hJSONCollection, 'Release')
    end
       
    Response = JSON
End Service
