import * as MsClient from "cn.keytop.midend.microservice.Client";


export class MsMng {

    private msId: string = 'cn.keytop.stc.test.ms-mng';
    private version: string = '2.0';
    private authType: MsClient.AuthType = MsClient.AuthType.BASE;
    protected serviceClientConfig: MsClient.ServiceClientConfig;
    protected serviceClient: MsClient.ServiceClient;

    constructor(serviceClientConfig: MsClient.ServiceClientConfig) {
        this.serviceClientConfig = serviceClientConfig;
        this.serviceClient = new MsClient.ServiceClientImpl(this.serviceClientConfig)
    }

    async getTest1(param1: string, param2: string): Promise<ModelTest1> {
        let uri = '/msServiceTest/getTest1'
        let sid = `${this.msId}.${uri}`
        let tags = ''
        let header = {}
        let paramMap = {'param1': param1, 'param2': param2}
        return await this.serviceClient.get(sid, this.version, tags, header, paramMap, this.authType)
    }

    async getTest3(param1: string, param2: string): Promise<OpResult<Post2Param>> {
        let uri = '/msServiceTest/getTest3'
        let sid = `${this.msId}.${uri}`
        let tags = ''
        let header = {}
        let paramMap = {'param1': param1, 'param2': param2}
        return await this.serviceClient.get(sid, this.version, tags, header, paramMap, this.authType)
    }

    async getTest5(param1: string, param2: string): Promise<OpResult<GetTest5Result>> {
        let uri = '/msServiceTest/getTest5'
        let sid = `${this.msId}.${uri}`
        let tags = ''
        let header = {}
        let paramMap = {'param1': param1, 'param2': param2}
        return await this.serviceClient.get(sid, this.version, tags, header, paramMap, this.authType)

    }


    async postTest2(bodyObj: Post2Param): Promise<OpResult<Post2Result>> {
        let uri = '/msServiceTest/postTest2'
        let sid = `${this.msId}.${uri}`
        let tags = ''
        let header = {}
        let paramMap = {}
        return await this.serviceClient.post(sid, this.version, tags, header, paramMap, bodyObj, this.authType, MsClient.RequestBodyType.RAW_JSON)
    }

}

export class ModelTest1 {
    value11?: string
    value12?: string
    sub?: ModelSubTest1
}

export class ModelSubTest1 {
    p1?: string
    p2?: string
}

export class ModelTest2 {
    value21?: string
    value22?: string
}

export class Post2Param {
    uri?: string
    param1?: string
    param2?: string
    _date?: number

    get date(): any {
        if (this._date) {
            return new Date(this._date)
        } else {
            return
        }
    }

    set date(value) {
        this._date = value
    }
}

export class Post2Result {
    body?: string
}

export class OpResult<T> {
    success?: string
    msg?: string
    message?: string
    code?: string
    data?: T
}

export class GetTest5Result {
    thisTimestamp?: string
    _thisLong?: number

    get thisLong(): any {
        console.log('get thisLong ')
        if (this._thisLong) {
            return new Date(this._thisLong)
        } else {
            return
        }
    }

    set thisLong(value) {
        console.log('set thisLong ')
        this._thisLong = value
    }
}