package com.red.circle.other.infra.database.mongo.document;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 火箭发射历史文档
 *
 * @author system
 * @date 2025-01-15
 */
@Data
@Document(collection = "rocket_launch_history")
@CompoundIndex(name = "idx_room_date_launch", def = "{'roomId': 1, 'date': 1, 'launchTime': -1}")
public class RocketHistoryDocument {

    @Id
    private String id;

    @Field("room_id")
    private Long roomId;

    @Field("date")
    private String date;

    @Field("level")
    private Integer level;

    @Field("final_energy")
    private Long finalEnergy;

    @Field("over_energy")
    private Long overEnergy;

    @Field("contributors")
    private List<HistoryContributor> contributors;

    @Field("total_contributors")
    private Integer totalContributors;

    @Field("reward_pool")
    private RewardPool rewardPool;

    @Field("claim_stats")
    private ClaimStats claimStats;

    @Field("claimedCount")
    private Integer claimedCount;

    @Field("launch_time")
    private LocalDateTime launchTime;

    @Field("claim_start_time")
    private LocalDateTime claimStartTime;

    @Field("claim_end_time")
    private LocalDateTime claimEndTime;

    @Field("created_at")
    private LocalDateTime createdAt;

    @Field("updated_at")
    private LocalDateTime updatedAt;

    @Data
    public static class HistoryContributor {
        @Field("user_id")
        private Long userId;

        @Field("user_name")
        private String userName;

        @Field("user_avatar")
        private String userAvatar;

        @Field("energy")
        private Long energy;

        @Field("contribution_rate")
        private Double contributionRate;

        @Field("rank")
        private Integer rank;
    }

    @Data
    public static class RewardPool {
        @Field("total_gold")
        private Long totalGold;

        @Field("contributor_gold")
        private Long contributorGold;

        @Field("normal_gold")
        private Long normalGold;
    }

    @Data
    public static class ClaimStats {
        @Field("total_claimed")
        private Integer totalClaimed;

        @Field("contributor_claimed")
        private Integer contributorClaimed;

        @Field("normal_claimed")
        private Integer normalClaimed;

        @Field("total_reward_sent")
        private Long totalRewardSent;
    }
}
