Function Semi_Vend_Code_Services(@Service, @Params)
/***********************************************************************************************************************

    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 Infineon Technologies.

    Name        :   Semi_Vend_Code_Services

    Description :   Handler program for all module related services.

    Notes       :   The generic parameters should contain all the necessary information to process the services. Often
                    this will be information like the data Record and Key ID.

    Parameters  :
        Service         [in] -- Name of the service being requested
        Param1-10   [in/out] -- Additional request parameter holders
        Response       [out] -- Response to be sent back to the Controller (MCP) or requesting procedure

    Metadata    :

    History     :   (Date, Initials, Notes)
        09/12/2025    djs     Created service module for OI Wizard Receive and Release operations.

***********************************************************************************************************************/
#pragma precomp SRP_PreCompiler

$Insert APP_INSERTS
$Insert SERVICE_SETUP
$Insert SEMI_VEND_CODE_EQUATES

Declare function   Database_Services, SRP_Json
Declare subroutine Error_Services, SRP_Json

GoToService else
    Error_Services('Set', Service : ' is not a valid service request within the ' : ServiceModule : ' services module.')
end

Return Response else ''

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Service Parameter Options
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Options BOOLEAN     = True$, False$

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Services
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//----------------------------------------------------------------------------------------------------------------------
// GetSemiVendCodes
//
// Returns an @FM delimited array of all SEMI_VEND_CD keys in the table.
//----------------------------------------------------------------------------------------------------------------------
Service GetSemiVendCodes()

    ErrorMsg      = ''
    SemiVendCodes = ''
    Open 'SEMI_VEND_CODE' to hTable then
        Select hTable
        EOF           = False$
        SemiVendCodes = ''
        Loop
            Readnext KeyId else EOF = True$
        Until EOF
            SemiVendCodes<-1> = KeyId
        Repeat
    end else
        ErrorMsg = 'Error in ':Service:' service. Error opening SEMI_VEND_CODE table.'
    end
    If ErrorMsg NE '' then Error_Services('Add', ErrorMsg)
    Response = SemiVendCodes

end service


Service ConvertRecordToJSON(KeyId, Record)
    
    ErrorMsg   = ''
    JsonRecord = ''
    If KeyId NE '' then
        If Record EQ '' then Record = Database_Services('ReadDataRow', 'SEMI_VEND_CODE', KeyId)
        If Error_Services('NoError') then
            // Create the JSON response object
            objJSON = ''
            If SRP_JSON(objJSON, 'New', 'Object') then
                objSemiVendCode = ''
                If SRP_JSON(objSemiVendCode, 'New', 'Object') then
                    SRP_JSON(objSemiVendCode, 'SetValue', 'VendCd', KeyId)
                    SRP_JSON(objSemiVendCode, 'SetValue', 'VendorName', Record<SEMI_VEND_CODE_VENDOR_NAME$>)
                    SRP_JSON(objSemiVendCode, 'SetValue', 'Location', Record<SEMI_VEND_CODE_LOCATION$>)
                    SRP_JSON(objSemiVendCode, 'SetValue', 'EpiVendCd', Record<SEMI_VEND_CODE_EPI_VEND_CD$>)
                    SRP_JSON(objJSON, 'Set', 'SemiVendCode', objSemiVendCode)
                    SRP_JSON(objSemiVendCode, 'Release')
                end
                jsonRecord = SRP_JSON(objJSON, 'Stringify', 'Styled')
                SRP_JSON(objJSON, 'Release')
            end else
                ErrorMsg = 'Error in ':Service:' service. Unable to create JSON object'
            end                    
        end else
            ErrorMsg = 'Error in ':Service:' service. Error message: ':Error_Services('GetMessage')
        end
    end else
        ErrorMsg = 'Error in ':Service:' service. Null KeyId passed into service.'
    end
    
    If ErrorMsg NE '' then Error_Services('Add', ErrorMsg)
    Response = JsonRecord
    
end service


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Internal GoSubs
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ClearCursors:
	
    For counter = 0 to 8
        ClearSelect counter
    Next counter
    
return

