using RpgRoller.Domain;

namespace RpgRoller.Services;

public static class GameStateCloneFactory
{
    public static UserAccount CloneUser(UserAccount user)
    {
        return new()
        {
            Id = user.Id,
            Username = user.Username,
            UsernameNormalized = user.UsernameNormalized,
            PasswordHash = user.PasswordHash,
            DisplayName = user.DisplayName,
            Roles = user.Roles,
            ActiveCharacterId = user.ActiveCharacterId
        };
    }

    public static UserSession CloneSession(UserSession session)
    {
        return new()
        {
            Token = session.Token,
            UserId = session.UserId,
            CreatedAtUtc = session.CreatedAtUtc
        };
    }

    public static Campaign CloneCampaign(Campaign campaign)
    {
        return new()
        {
            Id = campaign.Id,
            GmUserId = campaign.GmUserId,
            Name = campaign.Name,
            Ruleset = campaign.Ruleset,
            Version = campaign.Version
        };
    }

    public static Character CloneCharacter(Character character)
    {
        return new()
        {
            Id = character.Id,
            OwnerUserId = character.OwnerUserId,
            CampaignId = character.CampaignId,
            Name = character.Name
        };
    }

    public static Skill CloneSkill(Skill skill)
    {
        return new()
        {
            Id = skill.Id,
            CharacterId = skill.CharacterId,
            SkillGroupId = skill.SkillGroupId,
            Name = skill.Name,
            DiceRollDefinition = skill.DiceRollDefinition,
            WildDice = skill.WildDice,
            AllowFumble = skill.AllowFumble,
            FumbleRange = skill.FumbleRange,
            RolemasterAutoRetry = skill.RolemasterAutoRetry
        };
    }

    public static SkillGroup CloneSkillGroup(SkillGroup skillGroup)
    {
        return new()
        {
            Id = skillGroup.Id,
            CharacterId = skillGroup.CharacterId,
            Name = skillGroup.Name,
            DiceRollDefinition = skillGroup.DiceRollDefinition,
            WildDice = skillGroup.WildDice,
            AllowFumble = skillGroup.AllowFumble,
            FumbleRange = skillGroup.FumbleRange
        };
    }

    public static RollLogEntry CloneRollLogEntry(RollLogEntry entry)
    {
        return new()
        {
            Id = entry.Id,
            CampaignId = entry.CampaignId,
            CharacterId = entry.CharacterId,
            SkillId = entry.SkillId,
            RollerUserId = entry.RollerUserId,
            Visibility = entry.Visibility,
            Result = entry.Result,
            Breakdown = entry.Breakdown,
            Dice = entry.Dice,
            TimestampUtc = entry.TimestampUtc
        };
    }
}