import { RewardState } from "../GameData";

/**
 * @description 签到数据
 * @author 邹勇 薛鸿潇
 */
export class SignData {
    /** 标志位：是否需要刷新数据 */
    public init_data: boolean = false;

    /** 配置数据 签到 */
    public c_sign = [];

    // 服务端数据 上次签到天数
    private _sign_last_bar = 3;
    set sign_last_bar(value: number) {
        this._sign_last_bar = value;
        this.init_data = true;
    }
    get sign_last_bar(): number {
        return this._sign_last_bar;
    }

    // 服务端数据 能够签到
    private _sign_can = 1;
    set sign_can(value: number) {
        this._sign_can = value;
        this.init_data = true;
    }
    get sign_can(): number {
        return this._sign_can;
    }

    /** 签到列表数据 */
    public list_data = [];
    /** 初始化列表数据 */
    public initListData() {
        if (!this.c_sign.length) this.c_sign = this.getSignConfig();
        let list_data = [];
        for (let i = 0; i < 30;) {
            let item_data = [];
            for (let j = 0; j < 3; j++) {
                let data = this.c_sign[i];
                item_data.push(data);
                i++;
            }
            list_data.push(item_data);
        }
        this.list_data = list_data;
    }

    /** 客户端造的假配置 */
    private getSignConfig() {
        let c_sign = [];
        for (let i = 0; i < 30; i++) {
            const id = i + 1;
            let data: any = {};
            data.id = id;
            data.reward_type = i % 3;
            data.count = id;
            data.login_day = id;
            data.video_limit = 0;
            c_sign.push(data);
        }
        return c_sign;
    }

    /**
     * 获取奖励状态
     * @param login_day 登陆日 
     * @returns 状态123
     */
    public getStateByDay(login_day: number) {
        let _state = RewardState.none;
        if (login_day <= this.sign_last_bar) {
            _state = RewardState.none;
        } else if (login_day == (this.sign_last_bar + 1)) {
            if (!this.sign_can) {
                _state = RewardState.none;
            } else {
                _state = RewardState.unlock;
            }
        } else {
            _state = RewardState.lock;
        }
        return _state;
    }
}