package com.cooleshow.base.rx

import com.cooleshow.base.rx.BaseException
import com.cooleshow.base.common.ResultCode
import com.cooleshow.base.data.protocol.BaseResp
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.functions.Function
import rx.functions.Func1

/*
    Boolean类型转换封装
 */
//class BaseFuncBoolean<T>: Func1<BaseResp<T>, Observable<Boolean>> {
//    override fun call(t: BaseResp<T>): Observable<Boolean> {
//        if (t.status != ResultCode.SUCCESS){
//            return Observable.error(BaseException(t.status, t.message))
//        }
//
//        return Observable.just(true)
//    }
//}

class BaseFuncBoolean<T>: Function<BaseResp<T>, Observable<Boolean>> {
    override fun apply(t: BaseResp<T>): Observable<Boolean> {
        if (t.status != ResultCode.SUCCESS){
            return Observable.error(BaseException(t.status, t.message))
        }

        return Observable.just(true)
    }
}