using Domain.SeedWork;
using Framework.DataType;
using Resources.Messages;

namespace Domain.Aggregates.Users;

public class User : Entity
{
    public User()
    {
        // FOR EF!
    }

    private User(string username, string password, string mobile)
    {
        Username = username;
        Password = password;
        Mobile = mobile;
    }


    public string Username { get; private set; }
    public string Password { get; private set; }
    public string Mobile { get; private set; }

    public static User Create(string username, string password, string mobile)
    {
        if (!mobile.IsValidMobile())
        {
            var message =
                string.Format(Errors.Invalid, Resources.DataDictionary.CellPhonenumber);

            throw new InvalidDataException(message);
        }

        var user = new User(
            username: username.Fix() ?? "",
            password: password.Fix() ?? "",
            mobile: mobile);

        return user;
    }

    public void Update(string username, string password, string mobile)
    {
        if (!mobile.IsValidMobile())
        {
            var message =
                string.Format(Errors.Invalid, Resources.DataDictionary.CellPhonenumber);

            throw new InvalidDataException(message);
        }

        Username = username.Fix() ?? "";
        Password = password.Fix() ?? "";
        Mobile = mobile;

        SetUpdateDateTime();
    }
}
