
/**
 * 引用鸿蒙系统库，示例如下：
 * import deviceInfo from "@ohos.deviceInfo";
 * [可选实现，按需引入]
 */

/* 引入 interface.uts 文件中定义的变量 */
import { AppAuthOptions, MyApiOptions , MyApiResult, MyApiSync, MyApi, getAuthorizationIntent ,endSession} from '../interface.uts';
import { AppAuthManager , AppAuthCallback} from 'authncenter/src/main/ets/components/AppAuthManager';
import { promptAction } from '@kit.ArkUI';


const TAG : string = "RJ-AppAuthnCenter";
export {
  AppAuthOptions
}

let myApiOptions : MyApiOptions | undefined;
export class  RJAppAuthCallback implements AppAuthCallback
{
	OnSuccess(token: string): void {
		if(myApiOptions&&myApiOptions.success)
		{
			myApiOptions.success(token)
		}
	}
	OnError(code: number, message: string): void {
		__f__('log','at uni_modules/RJ-AppAuthnCenter/utssdk/app-harmony/index.uts:29',"RJAppAuthCallback , error="+message)
		if(myApiOptions&&myApiOptions.fail)
		{
			myApiOptions.fail(code , message)
		}
	}
}


let appCallback : RJAppAuthCallback = new RJAppAuthCallback();
let appEndSessionCallback : RJAppAuthCallback = new RJAppAuthCallback();

export const innerGetAuthorizationIntent : getAuthorizationIntent = function(
	appId : string , 
	redirectUrl : string , 
	discoveryUrl : string , 
	scheme : string , 
	bundleName : string,
	options: MyApiOptions)
{	
	__f__('log','at uni_modules/RJ-AppAuthnCenter/utssdk/app-harmony/index.uts:49',TAG,"innerGetAuthorizationIntent redirectURl = " + redirectUrl + " discoveryUrl=" +discoveryUrl + ";scheme=" + scheme + ";bundleName" + bundleName)
		
	myApiOptions = options;
				
	//AppAuthManager.getInstance().getAuthorizationIntent( appId , redirectUrl, discoveryUrl , scheme , bundleName,
	//            appCallback);
				
	AppAuthManager.getInstance().getAuthorizationIntentDirectly( appId , redirectUrl, "https://s10sso.ruishan.cc/cas/oidc/authorize" , "https://s10sso.ruishan.cc/cas/oidc/accessToken",scheme , bundleName,
	            appCallback);

}

export const innerEndSession : endSession = function (
	endSessionEndpoint : string , 
	redirectUrl : string , 
	scheme : string , 
	bundleName : string
	options: MyApiOptions) 
{
	
	__f__('log','at uni_modules/RJ-AppAuthnCenter/utssdk/app-harmony/index.uts:69',TAG,"innerEndSession redirectURl = " + redirectUrl + " endSessionEndpoint=" +endSessionEndpoint + ";scheme=" + scheme + ";bundleName" + bundleName)
	
	myApiOptions = options;
	AppAuthManager.getInstance().EndSession(endSessionEndpoint,redirectUrl
		    ,scheme ,bundleName ,appEndSessionCallback)

}