package com.red.circle.other.infra.database.mongo.entity.game;

import java.io.Serializable;
import java.sql.Timestamp;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

/**
 * 用户游戏游玩历史.
 *
 * @author tf
 */
@Data
@Accessors(chain = true)
@Document("user_game_play_history")
@CompoundIndexes({
    @CompoundIndex(name = "idx_user_play_time", def = "{'userId': 1, 'playTime': -1}"),
    @CompoundIndex(name = "idx_user_game", def = "{'userId': 1, 'gameListConfigId': 1}", unique = true)
})
public class UserGamePlayHistory implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private String id;

    private String sysOrigin;

    private Long userId;

    /** GameListConfig 主键 */
    private Long gameListConfigId;

    /** 游戏信息快照 */
    private GameInfo gameInfo;

    /** 最近游玩时间 */
    @Indexed
    private Timestamp playTime;

    /** 过期时间，90天TTL自动清理 */
    @Indexed(expireAfterSeconds = 0)
    private Timestamp expiredTime;

    @Data
    public static class GameInfo {
        private Long id;
        private String gameId;
        private String gameOrigin;
        private String gameMode;
        private String name;
        private String cover;
        private String gameCode;
        /**
         * 高
         */
        private Double height;

        /**
         * 宽
         */
        private Double width;
    }
}
