import type {Suit, Tile} from "../../types/tile.ts";

export class TileModel {
    id: number
    suit: Suit
    value: number

    constructor(tile: Tile) {
        this.id = tile.id
        this.suit = tile.suit
        this.value = tile.value
    }

    /** 花色中文 */
    get suitName(): string {
        const map: Record<Suit, string> = {
            W: '万',
            T: '筒',
            B: '条',
        }
        return map[this.suit]
    }

    /** 显示文本 */
    toString(): string {
        return `${this.suitName}${this.value}[#${this.id}]`
    }

    /** 是否同一张牌（和后端一致：按ID） */
    equals(other: TileModel): boolean {
        return this.id === other.id
    }

    /** 排序权重（用于手牌排序） */
    get sortValue(): number {
        const suitOrder: Record<Suit, number> = {
            W: 0,
            T: 1,
            B: 2,
        }
        return suitOrder[this.suit] * 10 + this.value
    }
}