public with sharing class LexStockCancelController {
    public LexStockCancelController() {
        
    }
    @AuraEnabled
    public static Opportunity init(String recordId){
    	try{
    		Opportunity item=[select 
    		 Stock_cancel_reason__c,Whether_Upload_Question_Document__c
    		 from Opportunity
    		 where id = :recordId];
    		return item;

    	}catch(Exception e){
    		System.debug('LexStockCancelController init error: '+e.getMessage());
    	}
    	return null;
    }

    @AuraEnabled
    public static UpdateResult updateOppotunity(        
        String recordId,
        String stStatus
    ) {
        UpdateResult result = new UpdateResult();
        result.recordId = recordId;
        try{
            Opportunity op=new Opportunity(id=recordId);
            if(stStatus!=null&&stStatus!=''){
            	op.Stock_apply_status__c= stStatus;
            }
            update op;
            result.success = true;
            result.errors = new List<String>();
            return result;
        }catch(Exception e){
            result.success = false;
            result.errors = new List<String>();
            result.errors.add(e.getMessage());
            System.debug(LoggingLevel.INFO,'updateOppotunity  Error : ' + e);
        }
        return result;
    }
    @AuraEnabled
	public static String submitApprovalRequest(String recordId) {
		try{
		   Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
		   req.setObjectId(recordId);
		   Approval.ProcessResult result = Approval.process(req);
		   if(result.getErrors()!=null&&result.getErrors().size()>0)return result.getErrors().get(0).getMessage();
		}catch(Exception e){
			System.debug('LexStockCancelController submitApprovalRequest  error: '+e.getMessage());
			return e.getMessage();
		}
	   	return null;
	}
    public class UpdateResult {
        @AuraEnabled public String recordId {get;set;}
        @AuraEnabled public Boolean success {get;set;}
        @AuraEnabled public List<String> errors {get;set;}
    }
	public class InitData{
       
    }
}