|
| 1 | +import type { SKUFlags, APISKU } from 'discord-api-types/v10'; |
| 2 | +import { Structure } from '../Structure.js'; |
| 3 | +import { SKUFlagsBitField } from '../bitfields/SKUFlagsBitField.js'; |
| 4 | +import { kData } from '../utils/symbols.js'; |
| 5 | +import { isFieldSet } from '../utils/type-guards.js'; |
| 6 | +import type { Partialize } from '../utils/types.js'; |
| 7 | + |
| 8 | +/** |
| 9 | + * Represents any SKU (stock-keeping units) on Discord. |
| 10 | + * |
| 11 | + * @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate` |
| 12 | + */ |
| 13 | +export class SKU<Omitted extends keyof APISKU | '' = ''> extends Structure<APISKU, Omitted> { |
| 14 | + /** |
| 15 | + * The template used for removing data from the raw data stored for each SKU |
| 16 | + */ |
| 17 | + public static override readonly DataTemplate: Partial<APISKU> = {}; |
| 18 | + |
| 19 | + /** |
| 20 | + * @param data - The raw data received from the API for the SKU |
| 21 | + */ |
| 22 | + public constructor(data: Partialize<APISKU, Omitted>) { |
| 23 | + super(data); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Id of the SKU |
| 28 | + */ |
| 29 | + public get id() { |
| 30 | + return this[kData].id; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Type of SKU |
| 35 | + * |
| 36 | + * @see {@link https://discord.com/developers/docs/resources/sku#sku-object-sku-types} |
| 37 | + */ |
| 38 | + public get type() { |
| 39 | + return this[kData].type; |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Id of the parent application |
| 44 | + */ |
| 45 | + public get applicationId() { |
| 46 | + return this[kData].application_id; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Customer-facing name of your premium offering |
| 51 | + */ |
| 52 | + public get name() { |
| 53 | + return this[kData].name; |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * System-generated URL slug based on the SKU's name |
| 58 | + */ |
| 59 | + public get slug() { |
| 60 | + return this[kData].slug; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * SKU flags combined as a bitfield |
| 65 | + */ |
| 66 | + public get flags() { |
| 67 | + return isFieldSet(this[kData], 'flags', 'number') ? new SKUFlagsBitField(this[kData].flags as SKUFlags) : null; |
| 68 | + } |
| 69 | +} |
0 commit comments