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

namespace Domain.Entities.Donations;

public class CrewMember
{
    [ForeignKey(nameof(CrewID))]
    public virtual Crew? Crew { get; private set; }

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

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

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

    public int CrewID { get; private set; }

    public int MemberID { get; private set; }

    public int? ChannelID { get; private set; }

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

    public string? Role { get; private set; }

    public int SortOrder { get; private set; }

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

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

    private CrewMember() { }

    public static CrewMember Create(int crewID, int memberID, string nickname, int? channelID = null, string? role = null, int sortOrder = 0)
    {
        return new CrewMember
        {
            CrewID = crewID,
            MemberID = memberID,
            ChannelID = channelID,
            Nickname = nickname,
            Role = role,
            SortOrder = sortOrder
        };
    }

    public void Update(string nickname, string? role, int sortOrder, bool isActive)
    {
        Nickname = nickname;
        Role = role;
        SortOrder = sortOrder;
        IsActive = isActive;
    }
}