using System.ComponentModel.DataAnnotations;

namespace LibraryAPI.DTOs
{
    // ── Book DTOs ────────────────────────────────────────────────────────────

    public class BookDto
    {
        public int Id { get; set; }
        public string Title { get; set; } = string.Empty;
        public string ISBN { get; set; } = string.Empty;
        public string? Genre { get; set; }
        public int PublishedYear { get; set; }
        public decimal Price { get; set; }
        public int TotalCopies { get; set; }
        public int AvailableCopies { get; set; }
        public bool IsAvailable => AvailableCopies > 0;
        public string? Description { get; set; }
        public DateTime CreatedAt { get; set; }

        // Author info (flat, no nested object)
        public int AuthorId { get; set; }
        public string AuthorFullName { get; set; } = string.Empty;
    }

    public class BookCreateDto
    {
        [Required]
        [MaxLength(200)]
        public string Title { get; set; } = string.Empty;

        [Required]
        [MaxLength(13)]
        public string ISBN { get; set; } = string.Empty;

        [MaxLength(100)]
        public string? Genre { get; set; }

        [Range(1000, 2100)]
        public int PublishedYear { get; set; }

        [Range(0, 99999.99)]
        public decimal Price { get; set; }

        [Range(1, 1000)]
        public int TotalCopies { get; set; } = 1;

        [MaxLength(1000)]
        public string? Description { get; set; }

        [Required]
        public int AuthorId { get; set; }
    }

    public class BookUpdateDto
    {
        [Required]
        [MaxLength(200)]
        public string Title { get; set; } = string.Empty;

        [Required]
        [MaxLength(13)]
        public string ISBN { get; set; } = string.Empty;

        [MaxLength(100)]
        public string? Genre { get; set; }

        [Range(1000, 2100)]
        public int PublishedYear { get; set; }

        [Range(0, 99999.99)]
        public decimal Price { get; set; }

        [Range(1, 1000)]
        public int TotalCopies { get; set; }

        [Range(0, 1000)]
        public int AvailableCopies { get; set; }

        [MaxLength(1000)]
        public string? Description { get; set; }

        [Required]
        public int AuthorId { get; set; }
    }

    // ── Book filter query params ──────────────────────────────────────────────

    public class BookFilterParams
    {
        public string? Title { get; set; }
        public string? Genre { get; set; }
        public int? AuthorId { get; set; }
        public bool? IsAvailable { get; set; }
        public int? PublishedYearFrom { get; set; }
        public int? PublishedYearTo { get; set; }
        public decimal? PriceMax { get; set; }
    }
}
