#nullable enable
using System;

namespace IGP.UnitySDK.GameKit
{
    // Response DTOs mirror the curio Runtime Leaderboard API service
    // (apps/api/src/runtime/dto/leaderboard-response.dto.ts).
    // Date fields are ISO date strings. Same-score ordering is not guaranteed,
    // and the entry list is not guaranteed to contain the requested count.

    [Serializable]
    public sealed class IGPLeaderboardUser
    {
        public string id = string.Empty;
        public string? nickname;
        public int? discriminator;
        public string? avatarUrl;
    }

    [Serializable]
    public sealed class IGPLeaderboardEntry
    {
        public int rank;
        public IGPLeaderboardUser user = new IGPLeaderboardUser();
        public long value;
    }

    [Serializable]
    public sealed class IGPLeaderboardMetadataItem
    {
        public int gameId;
        public string leaderboardId = string.Empty;
        public string period = IGPLeaderboardPeriod.Permanent;
        public string status = string.Empty;
        public string? displayName;
        public string? description;
        public object? config;
        public string createdAt = string.Empty;
        public string updatedAt = string.Empty;
    }

    [Serializable]
    public sealed class IGPListLeaderboardsByGameResult
    {
        public int gameId;
        public IGPLeaderboardMetadataItem[] leaderboards = Array.Empty<IGPLeaderboardMetadataItem>();
    }

    [Serializable]
    public sealed class IGPGetLeaderboardResult
    {
        public int gameId;
        public string leaderboardId = string.Empty;
        public string period = IGPLeaderboardPeriod.Permanent;
        public IGPLeaderboardEntry[] entries = Array.Empty<IGPLeaderboardEntry>();
        public IGPLeaderboardEntry? selfEntry;
        public string generatedAt = string.Empty;
    }

    [Serializable]
    public sealed class IGPSubmitLeaderboardScoreResult
    {
        public bool success;
        public bool duplicated; // true when an existing eventId short-circuited the write
        public long value;
    }

    [Serializable]
    public sealed class IGPLeaderboardScoreItem
    {
        public string userId = string.Empty;
        public long? value; // null when the user has never submitted a score
    }

    [Serializable]
    public sealed class IGPQueryLeaderboardScoresResult
    {
        public int gameId;
        public string leaderboardId = string.Empty;
        public string period = IGPLeaderboardPeriod.Permanent;
        public IGPLeaderboardScoreItem[] scores = Array.Empty<IGPLeaderboardScoreItem>();
        public string generatedAt = string.Empty;
    }
}
