export interface RoomDecorDefinition {
  decor_id: string;
  name: string;
  item_id: string;
  icon: string;
  texture?: string;
  default_scale: number;
  default_position: {
    x: number;
    y: number;
  };
  default_z_index: number;
  collision_size?: {
    x: number;
    y: number;
  };
  collision_offset?: {
    x: number;
    y: number;
  };
}

export interface RoomDecorLegacyDefault {
  scale: number;
  default_position: {
    x: number;
    y: number;
  };
}

export const ROOM_DECOR_ROOM_SCALE = 0.7;
export const ROOM_DECOR_BED_DEFAULT_SCALE = ROOM_DECOR_ROOM_SCALE;
export const ROOM_DECOR_BOOKSHELF_DEFAULT_SCALE = 0.12;
export const ROOM_DECOR_FLOOR_RUG_DEFAULT_SCALE = 1.0;
export const ROOM_DECOR_WALL_DECOR_DEFAULT_SCALE = 0.04;
export const ROOM_DECOR_LEGACY_BED_MAX_SCALE = 0.35;
export const ROOM_DECOR_LEGACY_WALL_DECOR_SCALES = [0.7, 0.18];

export const ROOM_DECOR_LEGACY_DEFAULTS: Record<string, RoomDecorLegacyDefault> = {
  whale_floor_rug: {
    scale: 0.42,
    default_position: { x: 0, y: 230 },
  },
  whale_memory_board: {
    scale: 0.16,
    default_position: { x: 260, y: -295 },
  },
  whale_tail_lamp: {
    scale: 0.16,
    default_position: { x: 330, y: -250 },
  },
  boat_cabin_bed: {
    scale: 1,
    default_position: { x: -230, y: 35 },
  },
  low_wave_bed: {
    scale: 1,
    default_position: { x: -140, y: 55 },
  },
  whale_tail_headboard_bed: {
    scale: 1,
    default_position: { x: 0, y: 45 },
  },
  dev_whale_bookshelf: {
    scale: 1,
    default_position: { x: -300, y: -55 },
  },
  datawhale_bug_feature_badge: {
    scale: 1,
    default_position: { x: -300, y: -290 },
  },
  datawhale_buddhist_learning_badge: {
    scale: 1,
    default_position: { x: 0, y: -290 },
  },
  datawhale_ok_working_badge: {
    scale: 1,
    default_position: { x: 300, y: -290 },
  },
};

export const ROOM_DECOR_DEFINITIONS: RoomDecorDefinition[] = [
  {
    decor_id: 'whale_floor_rug',
    item_id: 'decor_whale_floor_rug',
    name: '鲸浪地毯',
    icon: 'res://assets/ui/mall/items/room_decor_whale_floor_rug.png',
    texture: 'res://assets/maps/personal_space/v1/decor/room_decor_whale_floor_rug_roomfit.png',
    default_scale: ROOM_DECOR_FLOOR_RUG_DEFAULT_SCALE,
    default_position: { x: 0, y: 161 },
    default_z_index: -8,
  },
  {
    decor_id: 'whale_memory_board',
    item_id: 'decor_whale_memory_board',
    name: '鲸语记忆板',
    icon: 'res://assets/ui/mall/items/room_decor_whale_memory_board.png',
    default_scale: 0.11,
    default_position: { x: 182, y: -207 },
    default_z_index: -14,
  },
  {
    decor_id: 'whale_tail_lamp',
    item_id: 'decor_whale_tail_lamp',
    name: '鲸尾暖灯',
    icon: 'res://assets/ui/mall/items/room_decor_whale_tail_lamp.png',
    texture: 'res://assets/maps/personal_space/v1/decor/room_decor_whale_tail_lamp_roomfit.png',
    default_scale: 1,
    default_position: { x: 231, y: -175 },
    default_z_index: -10,
    collision_size: { x: 50, y: 32 },
    collision_offset: { x: 0, y: 56 },
  },
  {
    decor_id: 'boat_cabin_bed',
    item_id: 'decor_boat_cabin_bed',
    name: '船舱小床',
    icon: 'res://assets/ui/mall/items/room_decor_boat_cabin_bed.png',
    texture: 'res://assets/maps/personal_space/v1/decor/room_decor_boat_cabin_bed_roomfit.png',
    default_scale: ROOM_DECOR_BED_DEFAULT_SCALE,
    default_position: { x: -161, y: 25 },
    default_z_index: -9,
    collision_size: { x: 220, y: 112 },
    collision_offset: { x: 0, y: 52 },
  },
  {
    decor_id: 'low_wave_bed',
    item_id: 'decor_low_wave_bed',
    name: '海浪低床',
    icon: 'res://assets/ui/mall/items/room_decor_low_wave_bed.png',
    texture: 'res://assets/maps/personal_space/v1/decor/room_decor_low_wave_bed_roomfit.png',
    default_scale: ROOM_DECOR_BED_DEFAULT_SCALE,
    default_position: { x: -98, y: 39 },
    default_z_index: -9,
    collision_size: { x: 220, y: 112 },
    collision_offset: { x: 0, y: 56 },
  },
  {
    decor_id: 'whale_tail_headboard_bed',
    item_id: 'decor_whale_tail_headboard_bed',
    name: '鲸尾床头床',
    icon: 'res://assets/ui/mall/items/room_decor_whale_tail_headboard_bed.png',
    texture: 'res://assets/maps/personal_space/v1/decor/room_decor_whale_tail_headboard_bed_roomfit.png',
    default_scale: ROOM_DECOR_BED_DEFAULT_SCALE,
    default_position: { x: 0, y: 32 },
    default_z_index: -9,
    collision_size: { x: 214, y: 112 },
    collision_offset: { x: 0, y: 62 },
  },
  {
    decor_id: 'dev_whale_bookshelf',
    item_id: 'decor_dev_whale_bookshelf',
    name: '程序员鲸书架',
    icon: 'res://assets/ui/mall/items/room_decor_dev_whale_bookshelf.png',
    texture: 'res://assets/ui/mall/items/room_decor_dev_whale_bookshelf.png',
    default_scale: ROOM_DECOR_BOOKSHELF_DEFAULT_SCALE,
    default_position: { x: -210, y: -39 },
    default_z_index: -10,
    collision_size: { x: 626.667, y: 226.667 },
    collision_offset: { x: 0, y: 580 },
  },
  {
    decor_id: 'datawhale_bug_feature_badge',
    item_id: 'decor_datawhale_bug_feature_badge',
    name: 'BUG特性徽章',
    icon: 'res://assets/ui/mall/items/room_decor_datawhale_bug_feature_badge.png',
    texture: 'res://assets/maps/personal_space/v1/decor/room_decor_datawhale_bug_feature_badge_hires_clean.png',
    default_scale: ROOM_DECOR_WALL_DECOR_DEFAULT_SCALE,
    default_position: { x: -210, y: -203 },
    default_z_index: -14,
  },
  {
    decor_id: 'datawhale_buddhist_learning_badge',
    item_id: 'decor_datawhale_buddhist_learning_badge',
    name: '佛系学习徽章',
    icon: 'res://assets/ui/mall/items/room_decor_datawhale_buddhist_learning_badge.png',
    texture: 'res://assets/maps/personal_space/v1/decor/room_decor_datawhale_buddhist_learning_badge_hires_clean.png',
    default_scale: ROOM_DECOR_WALL_DECOR_DEFAULT_SCALE,
    default_position: { x: 0, y: -203 },
    default_z_index: -14,
  },
  {
    decor_id: 'datawhale_ok_working_badge',
    item_id: 'decor_datawhale_ok_working_badge',
    name: '已经在做徽章',
    icon: 'res://assets/ui/mall/items/room_decor_datawhale_ok_working_badge.png',
    texture: 'res://assets/maps/personal_space/v1/decor/room_decor_datawhale_ok_working_badge_hires_clean.png',
    default_scale: ROOM_DECOR_WALL_DECOR_DEFAULT_SCALE,
    default_position: { x: 210, y: -203 },
    default_z_index: -14,
  },
];

export function findRoomDecorDefinition(decorId?: string): RoomDecorDefinition | undefined {
  const normalizedDecorId = (decorId || '').trim();
  return ROOM_DECOR_DEFINITIONS.find((decor) => normalizedDecorId && decor.decor_id === normalizedDecorId);
}
