import { BIND_PHONE_STATUS } from '../../consts';
import { ActivityModelType } from '../../db/Activity';
import { ActivityBindPhoneRewardType } from '../../db/ActivityBindPhoneReward';
import { UserType } from '../../db/User';
import { ActivityBase } from './activityField';

// 数据库
interface BindPhoneDataInDb {
    rewards: string;
}

// 数据
export class BindPhoneData extends ActivityBase {
    rewards: string;

    status: number = BIND_PHONE_STATUS.WAIT_BIND;            // 状态 0-未绑定 1-已绑定可领取 2-已领取   

    constructor(activityData: ActivityModelType, createTime: number, serverTime: number) {
        super(activityData, createTime, serverTime);
        this.initData(activityData.data)
    }

    public initData(data: string) {
        let dataObj: BindPhoneDataInDb = JSON.parse(data);
        this.rewards = dataObj.rewards;
    }

    public setRecord(user: UserType, data: ActivityBindPhoneRewardType) {
        if(user && user.channelInfo && user.channelInfo.is_phone_bind == 1) this.status = BIND_PHONE_STATUS.HAS_BIND;
        if(data) this.status = data.status;
    }

    public getShowResult() {
        return {
            ...this.getBaseKeys(),
            rewards: this.rewards,
            status: this.status,
        }
    }

}