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

namespace Domain.Entities.Forum.Comments
{
    [Table("CommentImage")]
    [Index(nameof(BoardID))]
    [Index(nameof(PostID))]
    [Index(nameof(CommentID))]
    [Index(nameof(UUID), IsUnique = true)]
    [Index(nameof(CommentID), nameof(HashedName))]
    [Index(nameof(CommentID), nameof(HashedName), nameof(IsDisabled))]
    [Index(nameof(CommentID), nameof(HashedName), nameof(IsDisabled), nameof(ID))]
    public class CommentImage
    {
        [ForeignKey(nameof(BoardID))]
        public virtual Board Board { get; set; } = default!;

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

        [ForeignKey(nameof(CommentID))]
        public virtual Comment Comment { get; set; } = default!;

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

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

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

        [Comment("댓글 ID")]
        public int CommentID { get; set; }

        [Comment("이미지 ID")]
        public Guid UUID { get; set; } = Guid.NewGuid();

        [Comment("원본 파일명")]
        [StringLength(255)]
        public string FileName { get; set; } = null!;

        [Comment("저장 파일명")]
        [StringLength(255)]
        public string HashedName { get; set; } = null!;

        [Comment("저장 경로")]
        [StringLength(500)]
        public string Path { get; set; } = null!;

        [Comment("URL")]
        [StringLength(1000)]
        public string Url { get; set; } = null!;

        [Comment("확장자")]
        [StringLength(10)]
        public string? Extension { get; set; }

        [Comment("MIME 타입")]
        [StringLength(100)]
        public string? ContentType { get; set; }

        [Comment("용량(byte)")]
        public long? Size { get; set; }

        [Comment("가로 해상도(px)")]
        public short? Width { get; set; }

        [Comment("세로 해상도(px)")]
        public short? Height { get; set; }

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

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

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