var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { Weapon } from './Weapon';
import { Game } from '../Game';
import { Wait } from '../utils';
/**
 * weapon asset
 *
 */
export class WeaponAsset {
    constructor(hash) {
        this.hash = hash;
    }
    /**
     * get weapon hash
     *
     * @constructor
     */
    get Hash() {
        return this.hash;
    }
    /**
     * check weapon is valid
     *
     * @constructor
     */
    get IsValid() {
        return IsWeaponValid(this.hash);
    }
    /**
     * check weapon assets is loaded
     *
     * @constructor
     */
    get IsLoaded() {
        return HasWeaponAssetLoaded(this.hash);
    }
    /**
     * request weapon asset
     *
     */
    request() {
        RequestWeaponAsset(this.hash, 31, 0);
    }
    /**
     * request weapon asset async
     *
     * @param timeout
     */
    requestAsync(timeout) {
        return __awaiter(this, void 0, void 0, function* () {
            this.request();
            const start = GetGameTimer();
            while (!this.IsLoaded) {
                yield Wait(100);
                const now = GetGameTimer();
                if (now - start >= timeout) {
                    return false;
                }
            }
            return true;
        });
    }
    /**
     * unload weapon asset
     *
     */
    dismiss() {
        RemoveWeaponAsset(this.hash);
    }
    /**
     * get weapon display name / label
     *
     * @constructor
     */
    get DisplayName() {
        return Weapon.getDisplayNameFromHash(this.hash);
    }
    /**
     * get weapon localized name
     *
     * @constructor
     */
    get LocalizedName() {
        return Game.getGXTEntry(this.DisplayName);
    }
}
