using System.ComponentModel.DataAnnotations;

namespace Domain.Entities.Page.Banner
{
    public class BannerPosition
    {
        public virtual List<BannerItem> BannerItems { get; private set; } = [];

        [Key]
        public int ID { get; private set; }

        public string Code { get; private set; } = default!;

        public string Subject { get; private set; } = default!;

        public bool IsActive { get; private set; } = false;

        public DateTime? UpdatedAt { get; private set; }

        public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;

        private BannerPosition() { }

        private BannerPosition(string code, string subject, bool isActive)
        {
            if (string.IsNullOrWhiteSpace(code))
            {
                throw new ArgumentException("Code is required.", nameof(code));
            }

            if (code.Length > 30)
            {
                throw new ArgumentOutOfRangeException(nameof(code));
            }

            if (string.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentException("Subject is required.", nameof(subject));
            }

            if (subject.Length > 255)
            {
                throw new ArgumentOutOfRangeException(nameof(subject));
            }

            Code = code;
            Subject = subject;
            IsActive = isActive;
        }

        public static BannerPosition Create(string code, string subject, bool isActive = false)
        {
            return new(code, subject, isActive);
        }

        public void Update(string subject, bool isActive)
        {
            if (string.IsNullOrWhiteSpace(subject))
            {
                throw new ArgumentException("Subject is required.", nameof(subject));
            }

            if (subject.Length > 255)
            {
                throw new ArgumentOutOfRangeException(nameof(subject));
            }

            Subject = subject;
            IsActive = isActive;
            UpdatedAt = DateTime.UtcNow;
        }
    }
}