/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2014 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET VERIFY OFF
SET FEEDBACK OFF
SET SCAN OFF
WHENEVER OSERROR  EXIT FAILURE ROLLBACK
WHENEVER SQLERROR EXIT FAILURE ROLLBACK

DECLARE

  --
  -- Local constants and variables
  --
  l_SERVICE CONSTANT xxas_com_service_repository.service_name%TYPE
                       := 'Enrollment';
                       
BEGIN
      
  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'Manage goals' 
    ,p_path               => 'enrollment'    
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    );
    
    
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'submit'
    ,p_description        => 'Submits the enrollment for Sign-off'
    ,p_methods            => 'POST'
    ,p_path               => 'submit/{enrollmentId}'
    ,p_plsql              =>
      q'[
        DECLARE
        
          l_xml           XMLType;
          l_resp          xxas_http_resp_obj;
          l_request_xml   XMLType;          
          
        BEGIN
          l_request_xml := {requestBody};
          
          IF NOT xxas_com_sec_pkg.test_instance_rtn_boolean
            ('XXAS_DT_ENROL_SUBMIT', {pathParam.enrollmentId}) THEN
            
            l_resp := xxas_http_response
                        .status(xxas_http_resp_status_pkg.unauthorised)
                        .build();
             
          ELSE
          xxas_perf_plan_enrol_pkg.set_enr_status_to_pending({pathParam.enrollmentId});
          l_resp := xxas_http_response
                      .ok(xxas_com_msg_pkg.get_success_message_xml
                           (xxas_com_msg_type
                         (xxas_util_pkg.app, 'XXAS_COM_CHNG_SAVE', null)
                       ,'self')
                         )
                      .build();
         
         {response} := l_resp;
                  
         END IF;

        END
      ]'
    );   
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'signoff'
    ,p_description        => 'Sign-off the Enrollment'
    ,p_methods            => 'POST'
    ,p_path               => 'signoff/{enrollmentId}'
    ,p_plsql              =>
      q'[
        DECLARE
        
          l_xml           XMLType;
          l_resp          xxas_http_resp_obj;
          l_request_xml   XMLType;          
          
        BEGIN
          l_request_xml := {requestBody};
          
          IF NOT xxas_com_sec_pkg.test_instance_rtn_boolean
            ('XXAS_DT_ENROL_SIGNOFF', {pathParam.enrollmentId}) THEN
            
            l_resp := xxas_http_response
                        .status(xxas_http_resp_status_pkg.unauthorised)
                        .build();
             
          ELSE
          xxas_perf_plan_enrol_pkg.set_enr_status_to_approved({pathParam.enrollmentId});
          l_resp := xxas_http_response
                      .ok(xxas_com_msg_pkg.get_success_message_xml
                           (xxas_com_msg_type
                         (xxas_util_pkg.app, 'XXAS_COM_CHNG_SAVE', null)
                       ,'self')
                         )
                      .build();
         
         
                  
         END IF;
        
        {response} := l_resp; 
        
        END
      ]'
    );     

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'deletereview'
    ,p_description        => 'Delete a performance review'
    ,p_methods            => 'DELETE'
    ,p_path               => 'delete-review'
    ,p_plsql              =>
      q'[
        DECLARE
          l_xml           XMLType;
          l_resp          xxas_http_resp_obj;
          l_request_xml   XMLType;                    
        BEGIN
          l_request_xml := {requestBody};
          
          xxas_perf_review_pkg.delete_review_forms(l_request_xml);
            
          l_resp := xxas_http_response
                      .ok(xxas_com_msg_pkg.get_success_message_xml
                           (xxas_com_msg_type
                         (xxas_util_pkg.app, 'XXAS_COM_CHNG_SAVE', null)
                           )
                         )
                      .build();

         {response} := l_resp;
         
        END
      ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'cancelreview'
    ,p_description        => 'Cancel a performance review'
    ,p_methods            => 'POST'
    ,p_path               => 'cancel-review'
    ,p_plsql              =>
      q'[
        DECLARE
        
          l_xml           XMLType;
          l_resp          xxas_http_resp_obj;
          l_request_xml   XMLType;           
          
        BEGIN
          l_request_xml := {requestBody};
          
          xxas_perf_review_pkg.cancel_review_forms(l_request_xml);
            
          l_resp := xxas_http_response
                      .ok(xxas_com_msg_pkg.get_success_message_xml
                           (xxas_com_msg_type
                         (xxas_util_pkg.app, 'XXAS_COM_CHNG_SAVE', null)
                       ,'self')
                         )
                      .build();
         
         {response} := l_resp;
         
        END
      ]'
    );
    
END;

/
COMMIT;
EXIT;
