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: string
  name: string
  tags: any | null
  createdAt: Date
  updatedAt: Date
}

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

export type Item = {
  id: string
  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: string
  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: string
  effect: string
  strength: number
}

export type PlacedMapObject = {
  id: string
  mapObject: MapObject | string
  isRotated: boolean
  positionX: number
  positionY: number
}

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

export type MapEventTile = {
  id: string
  mapid: string
  type: MapEventTileType
  positionX: number
  positionY: number
  teleport?: MapEventTileTeleport
}

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

export type User = {
  id: string
  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: string
  name: string
  gender: CharacterGender
  race: CharacterRace
  isSelectable: boolean
  sprite?: Sprite
  createdAt: Date
  updatedAt: Date
}

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

export type Character = {
  id: string
  userid: string
  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
  isAttacking?: boolean
}

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

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

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

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

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

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

export type Chat = {
  id: string
  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: string
  characters: MapCharacter[]
}
