import { ROOM_DECOR_DEFINITIONS } from '../room_decor/room_decor_catalog';

export type MallItemType = 'skin' | 'room_decor';

export interface MallCatalogItem {
  itemId: string;
  itemType: MallItemType;
  skinId?: string;
  decorId?: string;
  icon?: string;
  name: string;
  category: string;
  description: string;
  price: number;
  tags: string[];
  sortOrder: number;
}

export const MALL_CATEGORIES = [
  { id: 'recommended', label: '推荐', icon: 'recommended' },
  { id: 'outfit', label: '装扮', icon: 'outfit' },
  { id: 'items', label: '道具', icon: 'items' },
  { id: 'companion', label: '伙伴', icon: 'companion' },
  { id: 'space', label: '空间', icon: 'space' },
  { id: 'limited', label: '限时', icon: 'limited' },
];

const ROOM_DECOR_MALL_ITEMS: MallCatalogItem[] = ROOM_DECOR_DEFINITIONS.map((definition) => ({
  itemId: definition.item_id,
  itemType: 'room_decor',
  decorId: definition.decor_id,
  icon: definition.icon,
  name: definition.name,
  category: definition.shop.category,
  description: definition.shop.description,
  price: definition.shop.price,
  tags: definition.shop.tags,
  sortOrder: definition.shop.sort_order,
}));

export const MALL_ITEMS: MallCatalogItem[] = [
  {
    itemId: 'skin_classic_whale',
    itemType: 'skin',
    skinId: 'classic_whale',
    name: '经典鲸鱼',
    category: 'outfit',
    description: '圆润、轻快的鲸鱼居民皮肤，适合喜欢海洋感角色的玩家。',
    price: 680,
    tags: ['可预览', '永久', '皮肤'],
    sortOrder: 10,
  },
  {
    itemId: 'skin_human_whale_directional_v2_8x4',
    itemType: 'skin',
    skinId: 'human_whale_directional_v2_8x4',
    name: '海风行者',
    category: 'outfit',
    description: '蓝白海风主题的人类角色皮肤，带有鲸鱼小镇风格的服装细节。',
    price: 680,
    tags: ['可预览', '永久', '皮肤'],
    sortOrder: 20,
  },
  {
    itemId: 'skin_girl_sailor_turnaround_v2_8x4',
    itemType: 'skin',
    skinId: 'girl_sailor_turnaround_v2_8x4',
    name: '海风少女',
    category: 'outfit',
    description: '水手风格的人类角色皮肤，适合轻松、清爽的 WhaleTown 日常。',
    price: 880,
    tags: ['可预览', '永久', '皮肤'],
    sortOrder: 30,
  },
  {
    itemId: 'skin_panda_hero_8x4',
    itemType: 'skin',
    skinId: 'panda_hero_8x4',
    icon: 'res://assets/ui/mall/skins/panda_hero_8x4_product.png',
    name: '熊猫侠',
    category: 'outfit',
    description: '黑白连帽外观的人类角色皮肤，四方向8帧动作，适合想要更鲜明角色辨识度的玩家。',
    price: 980,
    tags: ['可预览', '永久', '皮肤'],
    sortOrder: 40,
  },
  {
    itemId: 'skin_ordinary_man_male_8x4',
    itemType: 'skin',
    skinId: 'ordinary_man_male_8x4',
    icon: 'res://assets/ui/mall/skins/ordinary_man_male_8x4_product.png',
    name: '普通人(男)',
    category: 'outfit',
    description: '男性日常角色皮肤，四方向8帧动作，适合普通玩家形象。',
    price: 980,
    tags: ['可预览', '永久', '皮肤'],
    sortOrder: 50,
  },
	...ROOM_DECOR_MALL_ITEMS,
];

export const MALL_SKIN_ITEMS = MALL_ITEMS.filter((item) => item.itemType === 'skin' && item.skinId);

export function findMallItem(itemId?: string): MallCatalogItem | undefined {
  const normalizedItemId = (itemId || '').trim();
  return MALL_ITEMS.find((item) => normalizedItemId && item.itemId === normalizedItemId);
}

export function findMallSkinItem(itemId?: string): MallCatalogItem | undefined {
  const item = findMallItem(itemId);
  return item?.itemType === 'skin' && item.skinId ? item : undefined;
}
