import type { DiscordSku } from '@discordeno/types';
import type { Bot } from '../bot.js';
import type { DesiredPropertiesBehavior, SetupDesiredProps, TransformersDesiredProperties } from '../desiredProperties.js';
import type { Sku } from './types.js';

export function transformSku(bot: Bot, payload: DiscordSku): Sku {
  const props = bot.transformers.desiredProperties.sku;
  const sku = {} as SetupDesiredProps<Sku, TransformersDesiredProperties, DesiredPropertiesBehavior>;

  if (props.id && payload.id) sku.id = bot.transformers.snowflake(payload.id);
  if (props.type && payload.type) sku.type = payload.type;
  if (props.applicationId && payload.application_id) sku.applicationId = bot.transformers.snowflake(payload.application_id);
  if (props.name && payload.name) sku.name = payload.name;
  if (props.slug && payload.slug) sku.slug = payload.slug;
  if (props.flags && payload.flags) sku.flags = payload.flags;

  return bot.transformers.customizers.sku(bot, payload, sku);
}
