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

namespace Domain.Entities.Donations;

public class CrewWidgetConfig
{
    [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 CrewWidgetTheme Theme { get; private set; } = CrewWidgetTheme.Basic;

    public RankPeriodType Period { get; private set; }

    public DateTime? StartAt { get; private set; }

    public DateTime? EndAt { get; private set; }

    public int MaxDisplayCount { get; private set; } = 5;

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

    public bool IsShowDonationCount { get; private set; }

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

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

    public bool IsActive { get; private set; }

    public string BgColor { get; private set; } = "#1A1A2E";

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

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

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

    // ── 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 string? RowFontFamily { get; private set; }

    public int RowFontSizePx { get; private set; } = 14;

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

    public DateTime? UpdatedAt { get; private set; }

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

    private CrewWidgetConfig() { }

    public static CrewWidgetConfig Create(
        int channelID, int memberID, string title,
        CrewWidgetTheme theme, RankPeriodType period,
        DateTime? startAt, DateTime? endAt,
        int maxDisplayCount, bool isShowAmount, bool isShowDonationCount,
        bool isShowContributionRate, bool isShowMemberIcon, bool isActive,
        string bgColor,
        string? titleFontFamily, int titleFontSizePx, string titleFontColor,
        string? rank1FontFamily, int rank1FontSizePx, string rank1FontColor,
        string? rank2FontFamily, int rank2FontSizePx, string rank2FontColor,
        string? rank3FontFamily, int rank3FontSizePx, string rank3FontColor,
        string? rowFontFamily, int rowFontSizePx, string rowFontColor
    ) {
        return new CrewWidgetConfig
        {
            ChannelID = channelID, MemberID = memberID, Title = title,
            Theme = theme, Period = period, StartAt = startAt, EndAt = endAt,
            MaxDisplayCount = maxDisplayCount, IsShowAmount = isShowAmount,
            IsShowDonationCount = isShowDonationCount, IsShowContributionRate = isShowContributionRate,
            IsShowMemberIcon = isShowMemberIcon, IsActive = isActive, BgColor = bgColor,
            TitleFontFamily = titleFontFamily, TitleFontSizePx = titleFontSizePx, TitleFontColor = titleFontColor,
            Rank1FontFamily = rank1FontFamily, Rank1FontSizePx = rank1FontSizePx, Rank1FontColor = rank1FontColor,
            Rank2FontFamily = rank2FontFamily, Rank2FontSizePx = rank2FontSizePx, Rank2FontColor = rank2FontColor,
            Rank3FontFamily = rank3FontFamily, Rank3FontSizePx = rank3FontSizePx, Rank3FontColor = rank3FontColor,
            RowFontFamily = rowFontFamily, RowFontSizePx = rowFontSizePx, RowFontColor = rowFontColor
        };
    }

    public void Update(
        string title,
        CrewWidgetTheme theme, RankPeriodType period,
        DateTime? startAt, DateTime? endAt,
        int maxDisplayCount, bool isShowAmount, bool isShowDonationCount,
        bool isShowContributionRate, bool isShowMemberIcon, bool isActive,
        string bgColor,
        string? titleFontFamily, int titleFontSizePx, string titleFontColor,
        string? rank1FontFamily, int rank1FontSizePx, string rank1FontColor,
        string? rank2FontFamily, int rank2FontSizePx, string rank2FontColor,
        string? rank3FontFamily, int rank3FontSizePx, string rank3FontColor,
        string? rowFontFamily, int rowFontSizePx, string rowFontColor
    ) {
        Title = title; Theme = theme; Period = period;
        StartAt = startAt; EndAt = endAt;
        MaxDisplayCount = maxDisplayCount; IsShowAmount = isShowAmount;
        IsShowDonationCount = isShowDonationCount; IsShowContributionRate = isShowContributionRate;
        IsShowMemberIcon = isShowMemberIcon; IsActive = isActive; BgColor = bgColor;
        TitleFontFamily = titleFontFamily; TitleFontSizePx = titleFontSizePx; TitleFontColor = titleFontColor;
        Rank1FontFamily = rank1FontFamily; Rank1FontSizePx = rank1FontSizePx; Rank1FontColor = rank1FontColor;
        Rank2FontFamily = rank2FontFamily; Rank2FontSizePx = rank2FontSizePx; Rank2FontColor = rank2FontColor;
        Rank3FontFamily = rank3FontFamily; Rank3FontSizePx = rank3FontSizePx; Rank3FontColor = rank3FontColor;
        RowFontFamily = rowFontFamily; RowFontSizePx = rowFontSizePx; RowFontColor = rowFontColor;
        UpdatedAt = DateTime.UtcNow;
    }
}