/**
 * 游戏预约按钮相关接口、类
 */
import { callNativeSync } from './util';

/**
 * CardBtn类
 * @class CardBtn
 */
class CardBtn {
    constructor(id) {
        Object.defineProperties(this, {
            _cardBtnId: {
                value: id,
                enumerable: false,
                configurable: false
            },
            gameId: {
                set(gameId){
                    const res = callNativeSync('appGameCard.setGameId', { id: this._cardBtnId, gameId });
                    console.log(res, 'res')
                    if(res.code != 0) {
                        throw new Error(res)
                    }
                },
                get(){
                    const res = callNativeSync('appGameCard.getGameId', { id: this._cardBtnId});
                    console.log(res, 'res')
                    if(res.code != 0) {
                        throw new Error(res)
                    } else {
                        return res.data.value;
                    }
                }
            },
            sourceFrom: {
                get(){
                    const res = callNativeSync('appGameCard.getSourceFrom', { id: this._cardBtnId});
                    if(res.code != 0) {
                        throw new Error(res)
                    } else {
                        return res.data.value;
                    }
                }
            },
            biliFrom: {
                get(){
                    const res = callNativeSync('appGameCard.getBiliFrom', { id: this._cardBtnId});
                    if(res.code != 0) {
                        throw new Error(res)
                    } else {
                        return res.data.value;
                    }
                }
            },
            status: {
                get(){
                    const res = callNativeSync('appGameCard.getStatus', { id: this._cardBtnId});;
                    if(res.code != 0) {
                        throw new Error(res)
                    } else {
                        return res.data.value;
                    }
                }
            },
            reserveUrl: {
                get(){
                    const res = callNativeSync('appGameCard.getReserveUrl', { id: this._cardBtnId});
                    if(res.code != 0) {
                        throw new Error(res)
                    } else {
                        return res.data.value;
                    }
                },
                set(reserveUrl){
                    const res = callNativeSync('appGameCard.setReserveUrl', { id: this._cardBtnId, reserveUrl});
                    if(res.code != 0) {
                        throw new Error(res)
                    }
                    
                }
            },
            extra: {
                get(){
                    const res = callNativeSync('appGameCard.getExtra', { id: this._cardBtnId});
                    if(res.code != 0) {
                        throw new Error(res)
                    } else {
                        return res.data.value;
                    }
                },
                set(extra){
                    const res =  callNativeSync('appGameCard.setExtra', { id: this._cardBtnId, extra});
                    if(res.code != 0) {
                        throw new Error(res)
                    }
                }
            }

        })
    }
}

export default function createGameCardButton(id){
    return new CardBtn(id);
}
