using planli.backend.DTOs;
using planli.backend.Enums;
using System.ComponentModel.DataAnnotations;

namespace planli.backend.DTOs
{
    public static class ToDoValidation
    {
        public static IEnumerable<ValidationResult> ValidateRecurrence(bool isRecurring, Recurrence? recurrence)
        {
            if (isRecurring && recurrence == null)
                yield return new ValidationResult(
                    "A recurrence pattern is required for recurring tasks.",
                    new[] { "Recurrence" }
                );
        }
    }
    public class ToDoCreateDto : IValidatableObject
    {
        public required string Title {  get; set; }
        public string? Description { get; set; }
        public required ToDoPriority Priority { get; set; }
        public int BoardId { get; set; }
        public bool IsRecurring { get; set; }
        public Recurrence? Recurrence { get; set; }
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
            => ToDoValidation.ValidateRecurrence(IsRecurring, Recurrence);
    }

    public class ToDoUpdateDto : IValidatableObject
    {
        public string? Title { get; set; }
        public string? Description { get; set; }
        public ToDoPriority? Priority { get; set; }
        public CurrentToDoStatus? Status { get; set; }
        public bool IsRecurring { get; set; }
        public Recurrence? Recurrence { get; set; }
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
            => ToDoValidation.ValidateRecurrence(IsRecurring, Recurrence);
    }

    public class ToDoResponseDto
    {
        public int Id { get; set; }
        public required string Title { get; set; }
        public string? Description { get; set; }
        public ToDoPriority Priority { get; set; }
        public int BoardId { get; set; }
        public int UserId { get; set; }
        public CurrentToDoStatus Status { get; set; }
        public DateOnly CreatedAt { get; set; }
        public bool IsRecurring { get; set; }
        public Recurrence? Recurrence { get; set; }
    }
}
