
import { UserService } from "./services/UserService";
import { BalanceService } from "./services/BalanceService"
import type { RewardDTO } from "./domain/RewardDTO";
import { MCGenderEnum } from "./domain/MCGenderEnum";

export class MCOfferwallSDK {
    
    private static _apikey: any; 
    private static _userService: UserService;


    static init(apikey: string): void {
      this._apikey=apikey;
      this._userService = new UserService();
    }
  
   
    static getApikey(): string {
      return  this._apikey;
    }

    static async setUserId(uid: string): Promise<void> {
        await this._userService.setId(uid)
    }

    static async getUserId(): Promise<string> {
        return await this._userService.getOrCreateId()
    }

    
    static async setAdvertisingId(uid: string): Promise<void> {
      await this._userService.setAdvertisingId(uid)
    }

    static async getAdvertisingId(): Promise<string> {
      return await this._userService.getAdvertisingId()
    }

    static async setGender(gender: MCGenderEnum): Promise<void> {
      await this._userService.setGender(gender)
    }


    static async setAge(age: number): Promise<void> {
      await this._userService.setAge(age)
    }





    static async GetReward(adunit_id: string): Promise<RewardDTO | null> {
        const balanceService = new BalanceService();
        const uid = await this.getUserId();
    
        try {
          const reward = await balanceService.getBalance(uid, adunit_id);
          if (reward) {
            console.log('Reward received:', reward);
            return reward;
          } else {
            console.log('No reward received');
            return null;
          }
        } catch (error) {
          console.error('Error fetching balance:', error);
          throw error;
        }
      }


 }
