export type UUID = `${string}-${string}-${string}-${string}-${string}`

export type Notification = {
  id?: string
  title?: string
  message?: string
}

export type HttpResponse<T> = {
  success: boolean
  message?: string
  data?: T
}

export type TextureData = {
  key: string
  data: string // URL or Base64 encoded blob
  group: 'tiles' | 'map_objects' | 'sprites' | 'sprite_animations' | 'sound' | 'music' | 'ui' | 'font' | 'other'
  updatedAt: Date
  originX?: number
  originY?: number
  frameRate?: number
  frameWidth?: number
  frameHeight?: number
  frameCount?: number
}

export type Tile = {
  id: UUID
  name: string
  tags: any | null
  createdAt: Date
  updatedAt: Date
}

export type MapObject = {
  id: UUID
  name: string
  tags: any | null
  originX: number
  originY: number
  frameRate: number
  frameWidth: number
  frameHeight: number
  createdAt: Date
  updatedAt: Date
}

export type Item = {
  id: UUID
  name: string
  description: string | null
  itemType: ItemType
  stackable: boolean
  rarity: ItemRarity
  sprite?: Sprite
  createdAt: Date
  updatedAt: Date
}

export type ItemType = 'WEAPON' | 'HELMET' | 'CHEST' | 'LEGS' | 'BOOTS' | 'GLOVES' | 'RING' | 'NECKLACE'
export type ItemRarity = 'COMMON' | 'UNCOMMON' | 'RARE' | 'EPIC' | 'LEGENDARY'

export type Map = {
  id: UUID
  name: string
  width: number
  height: number
  tiles: string[][]
  pvp: boolean
  mapEffects: MapEffect[]
  mapEventTiles: MapEventTile[]
  placedMapObjects: PlacedMapObject[]
  characters: Character[]
  chats: Chat[]
  createdAt: Date
  updatedAt: Date
}

export type MapEffect = {
  id: UUID
  map: Map
  effect: string
  strength: number
}

export type PlacedMapObject = {
  id: UUID
  map: Map
  mapObject: MapObject
  depth: number
  isRotated: boolean
  positionX: number
  positionY: number
}

export enum MapEventTileType {
  BLOCK = 'BLOCK',
  TELEPORT = 'TELEPORT',
  NPC = 'NPC',
  ITEM = 'ITEM'
}

export type MapEventTile = {
  id: UUID
  mapId: UUID
  type: MapEventTileType
  positionX: number
  positionY: number
  teleport?: MapEventTileTeleport
}

export type MapEventTileTeleport = {
  id: UUID
  mapEventTile: MapEventTile
  toMap: Map
  toPositionX: number
  toPositionY: number
  toRotation: number
}

export type User = {
  id: UUID
  username: string
  password: string
  characters: Character[]
}

export enum CharacterGender {
  MALE = 'MALE',
  FEMALE = 'FEMALE'
}

export enum CharacterRace {
  HUMAN = 'HUMAN',
  ELF = 'ELF',
  DWARF = 'DWARF',
  ORC = 'ORC',
  GOBLIN = 'GOBLIN'
}

export type CharacterType = {
  id: UUID
  name: string
  gender: CharacterGender
  race: CharacterRace
  isSelectable: boolean
  sprite?: Sprite
  createdAt: Date
  updatedAt: Date
}

export type CharacterHair = {
  id: UUID
  name: string
  sprite?: Sprite
  gender: CharacterGender
  isSelectable: boolean
}

export type Character = {
  id: UUID
  userId: UUID
  user: User
  name: string
  hitpoints: number
  mana: number
  level: number
  experience: number
  alignment: number
  role: string
  positionX: number
  positionY: number
  rotation: number
  characterType: UUID | null
  characterHair: UUID | null
  map: UUID
  chats: Chat[]
  items: CharacterItem[]
  equipment: CharacterEquipment[]
}

export type MapCharacter = {
  character: Character
  isMoving: boolean
}

export type CharacterItem = {
  id: UUID
  character: Character
  item: Item
  quantity: number
}

export type CharacterEquipment = {
  id: UUID
  slot: CharacterEquipmentSlotType
  characterItem: CharacterItem
}

export enum CharacterEquipmentSlotType {
  HEAD = 'HEAD',
  BODY = 'BODY',
  ARMS = 'ARMS',
  LEGS = 'LEGS',
  NECK = 'NECK',
  RING = 'RING'
}

export type Sprite = {
  id: UUID
  name: string
  createdAt: Date
  updatedAt: Date
  spriteActions: SpriteAction[]
  characterTypes: CharacterType[]
}

export interface SpriteImage {
  url: string
  offset: {
    x: number
    y: number
  }
}

export type SpriteAction = {
  id: UUID
  sprite: Sprite
  action: string
  sprites: SpriteImage[]
  originX: number
  originY: number
  frameWidth: number
  frameHeight: number
  frameRate: number
}

export type Chat = {
  id: UUID
  character: Character
  map: Map
  message: string
  createdAt: Date
}

export type WorldSettings = {
  date: Date
  weatherState: WeatherState
}

export type WeatherState = {
  rainPercentage: number
  fogDensity: number
}

export type mapLoadData = {
  mapId: UUID
  characters: MapCharacter[]
}
