using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace bitforum.Models.Page.Banner
{
    [Table("BannerItem")]
    [Index(nameof(Order), Name = "IX_BannerItem_Order")]
    [Index(nameof(IsActive), Name = "IX_BannerItem_IsActive")]
    public class BannerItem
    {
        [ValidateNever]
        public virtual BannerPosition? BannerPosition { get; set; } = null;

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

        [Required]
        [ForeignKey("BannerPosition")]
        [DisplayName("배너 위치ID")]
        public int PositionID { get; set; }

        [Required]
        [DisplayName("배너 명")]
        [DataType(DataType.Text)]
        [MaxLength(255)]
        public string Subject { get; set; }

        [DisplayName("이미지")]
        [RegularExpression(@"\.(jpg|jpeg|png|gif)$", ErrorMessage = "이미지 파일은 jpg, jpeg, png, gif 형식이어야 합니다.")]
        [MaxLength(1024)]
        public string? Image { get; set; } = null;

        [DisplayName("가로 크기")]
        [Range(1, int.MaxValue, ErrorMessage = "숫자는 1 이상이어야 합니다.")]
        public int Width { get; set; } = 0;

        [DisplayName("세로 크기")]
        [Range(1, int.MaxValue, ErrorMessage = "숫자는 1 이상이어야 합니다.")]
        public int Height { get; set; } = 0;

        [DisplayName("주소")]
        [DataType(DataType.Url)]
        [MaxLength(255)]
        public string? Link { get; set; } = null;

        [Required]
        [DisplayName("순서")]
        public int Order { get; set; } = 0;

        [Required]
        [DisplayName("사용 여부")]
        public bool IsActive { get; set; } = false;

        [DisplayName("사용 기간 - 시작")]
        [DataType(DataType.DateTime)]
        public DateTime? StartAt { get; set; } = null;

        [DisplayName("사용 기간 - 종료")]
        [DataType(DataType.DateTime)]
        public DateTime? EndAt { get; set; } = null;

        [DisplayName("조회 수")]
        public int Views { get; set; } = 0;

        [DisplayName("수정일시")]
        [DataType(DataType.DateTime)]
        public DateTime? UpdatedAt { get; set; } = null;

        [DisplayName("등록일시")]
        [DataType(DataType.DateTime)]
        public DateTime? CreatedAt { get; set; } = null;
    }
}
