using Domain.Entities.Forum.Boards;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Domain.Entities.Forum.Posts
{
    [Table("PostMedia")]
    [Index(nameof(BoardID))]
    [Index(nameof(PostID))]
    [Index(nameof(Url))]
    [Index(nameof(PostID), nameof(CreatedAt))]
    public class PostMedia
    {
        [ForeignKey(nameof(BoardID))]
        public Board Board { get; set; } = null!;

        [ForeignKey(nameof(PostID))]
        public Post Post { get; set; } = null!;

        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [DisplayName("PK")]
        [Comment("PK")]
        public int ID { get; set; }

        [DisplayName("게시판 ID")]
        [Comment("게시판 ID")]
        public int BoardID { get; set; }

        [DisplayName("게시글 ID")]
        [Comment("게시글 ID")]
        public int PostID { get; set; }

        [DisplayName("URL")]
        [Comment("URL")]
        [DataType(DataType.Url)]
        [Url(ErrorMessage = "올바른 URL 형식이 아닙니다.")]
        [StringLength(1000, ErrorMessage = "{0}은 {1}자 이하로 입력하세요.")]
        public string Url { get; set; } = null!;

        [DisplayName("비활성 여부")]
        [Comment("비활성 여부")]
        public bool IsDisabled { get; set; } = false;

        [DisplayName("비활성 일시")]
        [Comment("비활성 일시")]
        [DataType(DataType.DateTime)]
        public DateTime? DisabledAt { get; set; } = null;

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