/**
 * @file Constants.js
 * @description Game constants and configuration values
 * @author Implementation Team
 */

/**
 * Board dimensions
 */
export const BOARD_SIZE = 8;
export const MIN_ROW = 0;
export const MAX_ROW = 7;
export const MIN_COL = 0;
export const MAX_COL = 7;

/**
 * Player colors
 */
export const COLORS = {
    WHITE: 'white',
    BLACK: 'black'
};

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

/**
 * Game status values
 */
export const GAME_STATUS = {
    ACTIVE: 'active',
    CHECK: 'check',
    CHECKMATE: 'checkmate',
    STALEMATE: 'stalemate',
    DRAW: 'draw',
    RESIGNED: 'resigned'
};

/**
 * Special move types
 */
export const SPECIAL_MOVES = {
    CASTLE_KINGSIDE: 'castle-kingside',
    CASTLE_QUEENSIDE: 'castle-queenside',
    EN_PASSANT: 'en-passant',
    PROMOTION: 'promotion'
};

/**
 * Unicode symbols for chess pieces
 */
export const PIECE_SYMBOLS = {
    [COLORS.WHITE]: {
        [PIECE_TYPES.KING]: '♔',
        [PIECE_TYPES.QUEEN]: '♕',
        [PIECE_TYPES.ROOK]: '♖',
        [PIECE_TYPES.BISHOP]: '♗',
        [PIECE_TYPES.KNIGHT]: '♘',
        [PIECE_TYPES.PAWN]: '♙'
    },
    [COLORS.BLACK]: {
        [PIECE_TYPES.KING]: '♚',
        [PIECE_TYPES.QUEEN]: '♛',
        [PIECE_TYPES.ROOK]: '♜',
        [PIECE_TYPES.BISHOP]: '♝',
        [PIECE_TYPES.KNIGHT]: '♞',
        [PIECE_TYPES.PAWN]: '♟'
    }
};

/**
 * FEN notation for piece types
 */
export const FEN_PIECES = {
    [COLORS.WHITE]: {
        [PIECE_TYPES.KING]: 'K',
        [PIECE_TYPES.QUEEN]: 'Q',
        [PIECE_TYPES.ROOK]: 'R',
        [PIECE_TYPES.BISHOP]: 'B',
        [PIECE_TYPES.KNIGHT]: 'N',
        [PIECE_TYPES.PAWN]: 'P'
    },
    [COLORS.BLACK]: {
        [PIECE_TYPES.KING]: 'k',
        [PIECE_TYPES.QUEEN]: 'q',
        [PIECE_TYPES.ROOK]: 'r',
        [PIECE_TYPES.BISHOP]: 'b',
        [PIECE_TYPES.KNIGHT]: 'n',
        [PIECE_TYPES.PAWN]: 'p'
    }
};

/**
 * Initial FEN position for standard chess
 */
export const INITIAL_FEN = 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1';

/**
 * File letters for algebraic notation
 */
export const FILES = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];

/**
 * Rank numbers for algebraic notation (from white's perspective)
 */
export const RANKS = ['8', '7', '6', '5', '4', '3', '2', '1'];

/**
 * Direction vectors for piece movement
 */
export const DIRECTIONS = {
    NORTH: { row: -1, col: 0 },
    SOUTH: { row: 1, col: 0 },
    EAST: { row: 0, col: 1 },
    WEST: { row: 0, col: -1 },
    NORTHEAST: { row: -1, col: 1 },
    NORTHWEST: { row: -1, col: -1 },
    SOUTHEAST: { row: 1, col: 1 },
    SOUTHWEST: { row: 1, col: -1 }
};

/**
 * Knight move offsets (L-shaped moves)
 */
export const KNIGHT_MOVES = [
    { 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 }
];

/**
 * King move offsets (one square in any direction)
 */
export const KING_MOVES = [
    { row: -1, col: -1 }, { row: -1, col: 0 }, { row: -1, col: 1 },
    { row: 0, col: -1 },                       { row: 0, col: 1 },
    { row: 1, col: -1 }, { row: 1, col: 0 }, { row: 1, col: 1 }
];

/**
 * Castling configuration
 */
export const CASTLING = {
    [COLORS.WHITE]: {
        KING_START: { row: 7, col: 4 },
        KINGSIDE: {
            ROOK_START: { row: 7, col: 7 },
            KING_END: { row: 7, col: 6 },
            ROOK_END: { row: 7, col: 5 }
        },
        QUEENSIDE: {
            ROOK_START: { row: 7, col: 0 },
            KING_END: { row: 7, col: 2 },
            ROOK_END: { row: 7, col: 3 }
        }
    },
    [COLORS.BLACK]: {
        KING_START: { row: 0, col: 4 },
        KINGSIDE: {
            ROOK_START: { row: 0, col: 7 },
            KING_END: { row: 0, col: 6 },
            ROOK_END: { row: 0, col: 5 }
        },
        QUEENSIDE: {
            ROOK_START: { row: 0, col: 0 },
            KING_END: { row: 0, col: 2 },
            ROOK_END: { row: 0, col: 3 }
        }
    }
};

/**
 * Game rule limits
 */
export const RULES = {
    FIFTY_MOVE_LIMIT: 50,           // Half-moves without pawn move or capture
    THREEFOLD_REPETITION_LIMIT: 3   // Same position repeated times
};

/**
 * Piece values for evaluation (in centipawns)
 */
export const PIECE_VALUES = {
    [PIECE_TYPES.PAWN]: 100,
    [PIECE_TYPES.KNIGHT]: 320,
    [PIECE_TYPES.BISHOP]: 330,
    [PIECE_TYPES.ROOK]: 500,
    [PIECE_TYPES.QUEEN]: 900,
    [PIECE_TYPES.KING]: 20000
};

export default {
    BOARD_SIZE,
    COLORS,
    PIECE_TYPES,
    GAME_STATUS,
    SPECIAL_MOVES,
    PIECE_SYMBOLS,
    FEN_PIECES,
    INITIAL_FEN,
    FILES,
    RANKS,
    DIRECTIONS,
    KNIGHT_MOVES,
    KING_MOVES,
    CASTLING,
    RULES,
    PIECE_VALUES
};
