/**
 * @file Constants.js
 * @description Game-wide constants for the chess game
 * @author Implementation Team
 */

/**
 * Board dimensions
 */
export const BOARD_SIZE = 8;

/**
 * Board boundaries
 */
export const BOARD_BOUNDS = Object.freeze({
  MIN_ROW: 0,
  MAX_ROW: 7,
  MIN_COL: 0,
  MAX_COL: 7
});

/**
 * Player colors
 */
export const COLORS = Object.freeze({
  WHITE: 'white',
  BLACK: 'black'
});

/**
 * Piece types
 */
export const PIECE_TYPES = Object.freeze({
  PAWN: 'pawn',
  ROOK: 'rook',
  KNIGHT: 'knight',
  BISHOP: 'bishop',
  QUEEN: 'queen',
  KING: 'king'
});

/**
 * Game status
 */
export const GAME_STATUS = Object.freeze({
  ACTIVE: 'active',
  CHECK: 'check',
  CHECKMATE: 'checkmate',
  STALEMATE: 'stalemate',
  DRAW: 'draw'
});

/**
 * Unicode symbols for chess pieces
 * Used for visual representation when not using images
 */
export const PIECE_SYMBOLS = Object.freeze({
  'white-king': '♔',
  'white-queen': '♕',
  'white-rook': '♖',
  'white-bishop': '♗',
  'white-knight': '♘',
  'white-pawn': '♙',
  'black-king': '♚',
  'black-queen': '♛',
  'black-rook': '♜',
  'black-bishop': '♝',
  'black-knight': '♞',
  'black-pawn': '♟'
});

/**
 * Initial piece positions in algebraic notation
 * Format: [piece_type, position]
 */
export const INITIAL_POSITIONS = Object.freeze({
  white: [
    // Pawns
    ['pawn', 'a2'], ['pawn', 'b2'], ['pawn', 'c2'], ['pawn', 'd2'],
    ['pawn', 'e2'], ['pawn', 'f2'], ['pawn', 'g2'], ['pawn', 'h2'],
    // Pieces
    ['rook', 'a1'], ['knight', 'b1'], ['bishop', 'c1'], ['queen', 'd1'],
    ['king', 'e1'], ['bishop', 'f1'], ['knight', 'g1'], ['rook', 'h1']
  ],
  black: [
    // Pawns
    ['pawn', 'a7'], ['pawn', 'b7'], ['pawn', 'c7'], ['pawn', 'd7'],
    ['pawn', 'e7'], ['pawn', 'f7'], ['pawn', 'g7'], ['pawn', 'h7'],
    // Pieces
    ['rook', 'a8'], ['knight', 'b8'], ['bishop', 'c8'], ['queen', 'd8'],
    ['king', 'e8'], ['bishop', 'f8'], ['knight', 'g8'], ['rook', 'h8']
  ]
});

/**
 * Piece values for AI evaluation
 */
export const PIECE_VALUES = Object.freeze({
  [PIECE_TYPES.PAWN]: 1,
  [PIECE_TYPES.KNIGHT]: 3,
  [PIECE_TYPES.BISHOP]: 3,
  [PIECE_TYPES.ROOK]: 5,
  [PIECE_TYPES.QUEEN]: 9,
  [PIECE_TYPES.KING]: 1000  // Infinite value (game over if lost)
});

/**
 * Event names for EventBus
 */
export const EVENTS = Object.freeze({
  PIECE_SELECTED: 'piece:selected',
  PIECE_DESELECTED: 'piece:deselected',
  PIECE_MOVED: 'piece:moved',
  PIECE_CAPTURED: 'piece:captured',
  PIECE_PROMOTED: 'piece:promoted',
  GAME_CHECK: 'game:check',
  GAME_CHECKMATE: 'game:checkmate',
  GAME_STALEMATE: 'game:stalemate',
  GAME_DRAW: 'game:draw',
  GAME_OVER: 'game:over',
  TURN_CHANGED: 'turn:changed',
  MOVE_INVALID: 'move:invalid'
});

/**
 * CSS class names
 */
export const CSS_CLASSES = Object.freeze({
  SQUARE_LIGHT: 'square--light',
  SQUARE_DARK: 'square--dark',
  SQUARE_SELECTED: 'square--selected',
  SQUARE_VALID_MOVE: 'square--valid-move',
  SQUARE_CHECK: 'square--check',
  SQUARE_LAST_MOVE: 'square--last-move',
  PIECE_DRAGGING: 'piece--dragging'
});

/**
 * AI difficulty levels
 */
export const AI_LEVELS = Object.freeze({
  EASY: { depth: 1, name: 'Easy' },
  MEDIUM: { depth: 2, name: 'Medium' },
  HARD: { depth: 3, name: 'Hard' },
  EXPERT: { depth: 4, name: 'Expert' }
});

/**
 * Direction vectors for piece movement
 * Used by sliding pieces (rook, bishop, queen)
 */
export const DIRECTIONS = Object.freeze({
  ORTHOGONAL: [
    { row: -1, col: 0 },  // Up
    { row: 1, col: 0 },   // Down
    { row: 0, col: -1 },  // Left
    { row: 0, col: 1 }    // Right
  ],
  DIAGONAL: [
    { row: -1, col: -1 }, // Up-left
    { row: -1, col: 1 },  // Up-right
    { row: 1, col: -1 },  // Down-left
    { row: 1, col: 1 }    // Down-right
  ],
  KNIGHT: [
    { row: -2, col: -1 }, { row: -2, col: 1 },
    { row: -1, col: -2 }, { row: -1, col: 2 },
    { row: 1, col: -2 },  { row: 1, col: 2 },
    { row: 2, col: -1 },  { row: 2, col: 1 }
  ]
});

/**
 * Files (columns) mapping
 */
export const FILES = Object.freeze({
  a: 0, b: 1, c: 2, d: 3, e: 4, f: 5, g: 6, h: 7
});

/**
 * Ranks (rows) mapping
 * Note: rank 1 is row 7 in our array (bottom of board)
 */
export const RANKS = Object.freeze({
  1: 7, 2: 6, 3: 5, 4: 4, 5: 3, 6: 2, 7: 1, 8: 0
});
