using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Domain.Entities.Donations.ValueObject;
using Domain.Entities.Members;

namespace Domain.Entities.Donations;

public class DonationRankConfig
{
    [ForeignKey(nameof(ChannelID))]
    public virtual Channel? Channel { get; private set; }

    [ForeignKey(nameof(MemberID))]
    public virtual Member? Member { get; private set; }

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

    public int ChannelID { get; private set; }

    public int MemberID { get; private set; }

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

    public RankThemeType Theme { get; private set; } = RankThemeType.Basic;

    public RankPeriodType Period { get; private set; }

    public DateTime? StartAt { get; private set; }

    public DateTime? EndAt { get; private set; }

    public bool IsShowAmount { get; private set; } = true;

    public int MaxRankCount { get; private set; } = DonationConstants.Rank.DefaultDisplayRank;

    public bool? NameMode { get; private set; }

    public bool IsActive { get; private set; }

    // ── 제목 폰트 ───────────────────────────────────
    public string? TitleFontFamily { get; private set; }

    public int TitleFontSizePx { get; private set; } = 18;

    public string TitleFontColor { get; private set; } = "#FFFFFF";

    // ── 이름 표시 유형 ──────────────────────────────
    public RankNameDisplayType NameDisplayType { get; private set; } = RankNameDisplayType.AccountNickname;

    // ── 표시 옵션 ───────────────────────────────────
    public bool IsShowDonationCount { get; private set; }

    public bool IsShowGradeIcon { get; private set; }

    public bool IsShowMemberIcon { get; private set; }

    // ── 1등 폰트 ────────────────────────────────────
    public string? Rank1FontFamily { get; private set; }

    public int Rank1FontSizePx { get; private set; } = 15;

    public string Rank1FontColor { get; private set; } = "#FFD700";

    // ── 2등 폰트 ────────────────────────────────────
    public string? Rank2FontFamily { get; private set; }

    public int Rank2FontSizePx { get; private set; } = 15;

    public string Rank2FontColor { get; private set; } = "#C0C0C0";

    // ── 3등 폰트 ────────────────────────────────────
    public string? Rank3FontFamily { get; private set; }

    public int Rank3FontSizePx { get; private set; } = 15;

    public string Rank3FontColor { get; private set; } = "#CD7F32";

    public DateTime? UpdatedAt { get; private set; }

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

    private DonationRankConfig() { }

    public static DonationRankConfig Create(
        int channelID, int memberID, string title,
        RankThemeType theme, RankPeriodType period,
        DateTime? startAt, DateTime? endAt,
        bool isShowAmount, int maxRankCount, bool? nameMode, bool isActive,
        string? titleFontFamily, int titleFontSizePx, string titleFontColor,
        RankNameDisplayType nameDisplayType,
        bool isShowDonationCount, bool isShowGradeIcon, bool isShowMemberIcon,
        string? rank1FontFamily, int rank1FontSizePx, string rank1FontColor,
        string? rank2FontFamily, int rank2FontSizePx, string rank2FontColor,
        string? rank3FontFamily, int rank3FontSizePx, string rank3FontColor
    ) {
        return new DonationRankConfig
        {
            ChannelID = channelID,
            MemberID = memberID,
            Title = title,
            Theme = theme,
            Period = period,
            StartAt = startAt,
            EndAt = endAt,
            IsShowAmount = isShowAmount,
            MaxRankCount = maxRankCount,
            NameMode = nameMode,
            IsActive = isActive,
            TitleFontFamily = titleFontFamily,
            TitleFontSizePx = titleFontSizePx,
            TitleFontColor = titleFontColor,
            NameDisplayType = nameDisplayType,
            IsShowDonationCount = isShowDonationCount,
            IsShowGradeIcon = isShowGradeIcon,
            IsShowMemberIcon = isShowMemberIcon,
            Rank1FontFamily = rank1FontFamily,
            Rank1FontSizePx = rank1FontSizePx,
            Rank1FontColor = rank1FontColor,
            Rank2FontFamily = rank2FontFamily,
            Rank2FontSizePx = rank2FontSizePx,
            Rank2FontColor = rank2FontColor,
            Rank3FontFamily = rank3FontFamily,
            Rank3FontSizePx = rank3FontSizePx,
            Rank3FontColor = rank3FontColor
        };
    }

    public void Update(
        string title,
        RankThemeType theme,
        RankPeriodType period,
        DateTime? startAt,
        DateTime? endAt,
        bool isShowAmount,
        int maxRankCount,
        bool? nameMode,
        bool isActive,
        string? titleFontFamily, int titleFontSizePx, string titleFontColor,
        RankNameDisplayType nameDisplayType,
        bool isShowDonationCount, bool isShowGradeIcon, bool isShowMemberIcon,
        string? rank1FontFamily, int rank1FontSizePx, string rank1FontColor,
        string? rank2FontFamily, int rank2FontSizePx, string rank2FontColor,
        string? rank3FontFamily, int rank3FontSizePx, string rank3FontColor
    ) {
        Title = title; Theme = theme; Period = period;
        StartAt = startAt; EndAt = endAt; IsShowAmount = isShowAmount;
        MaxRankCount = maxRankCount; NameMode = nameMode;
        IsActive = isActive;
        TitleFontFamily = titleFontFamily; TitleFontSizePx = titleFontSizePx; TitleFontColor = titleFontColor;
        NameDisplayType = nameDisplayType;
        IsShowDonationCount = isShowDonationCount; IsShowGradeIcon = isShowGradeIcon; IsShowMemberIcon = isShowMemberIcon;
        Rank1FontFamily = rank1FontFamily; Rank1FontSizePx = rank1FontSizePx; Rank1FontColor = rank1FontColor;
        Rank2FontFamily = rank2FontFamily; Rank2FontSizePx = rank2FontSizePx; Rank2FontColor = rank2FontColor;
        Rank3FontFamily = rank3FontFamily; Rank3FontSizePx = rank3FontSizePx; Rank3FontColor = rank3FontColor;
        UpdatedAt = DateTime.UtcNow;
    }
}