using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using Tiku.Application.Assets;

namespace Tiku.Api.Contracts;

public sealed class VideoSearchQueryDto
{
    [StringLength(100)]
    public string? Keyword { get; set; }

    public Guid? SubjectId { get; set; }

    [Range(1, 200)]
    public int? Limit { get; set; }

    public VideoSearchQuery ToQuery() => new(Keyword, SubjectId, Limit);
}

public sealed class VideoPlayDto
{
    [Required]
    public Guid VideoId { get; set; }

    public Guid? QuestionId { get; set; }

    public VideoPlayCommand ToCommand() => new(VideoId, QuestionId);
}

public sealed class VideoProgressDto
{
    [Required]
    public Guid VideoId { get; set; }

    public Guid? QuestionId { get; set; }

    [Range(0, int.MaxValue)]
    public int PositionSeconds { get; set; }

    [Range(0, int.MaxValue)]
    public int? DurationSeconds { get; set; }

    [Range(0, int.MaxValue)]
    public int? WatchedSeconds { get; set; }

    public bool? IsCompleted { get; set; }

    public JsonElement Metadata { get; set; } = JsonSerializer.SerializeToElement(new { });

    public VideoProgressCommand ToCommand()
    {
        return new VideoProgressCommand(
            VideoId,
            QuestionId,
            PositionSeconds,
            DurationSeconds,
            WatchedSeconds,
            IsCompleted,
            Metadata);
    }
}

public sealed class QuestionVideoQueryDto
{
    public Guid? QuestionId { get; set; }

    [MaxLength(100)]
    public IReadOnlyCollection<Guid>? QuestionIds { get; set; }

    [Range(1, 500)]
    public int? Limit { get; set; }

    public QuestionVideoQuery ToQuery() => new(QuestionId, QuestionIds, Limit);
}
