using System;
using System.Linq.Expressions;
using NetinaCMS.Domain.Dtos.SmallDto;
using NetinaCMS.Domain.Entities.Users;

namespace NetinaCMS.Domain.Mappers
{
    public static partial class ApplicationUserMapper
    {
        public static ApplicationUser AdaptToApplicationUser(this ApplicationUserSDto p1)
        {
            return p1 == null ? null : new ApplicationUser()
            {
                FirstName = p1.FirstName,
                LastName = p1.LastName,
                NationalId = p1.NationalId,
                BirthDate = p1.BirthDate,
                Gender = p1.Gender,
                SignUpStatus = p1.SignUpStatus,
                Id = p1.Id,
                Email = p1.Email,
                PhoneNumber = p1.PhoneNumber
            };
        }
        public static ApplicationUser AdaptTo(this ApplicationUserSDto p2, ApplicationUser p3)
        {
            if (p2 == null)
            {
                return null;
            }
            ApplicationUser result = p3 ?? new ApplicationUser();
            
            result.FirstName = p2.FirstName;
            result.LastName = p2.LastName;
            result.NationalId = p2.NationalId;
            result.BirthDate = p2.BirthDate;
            result.Gender = p2.Gender;
            result.SignUpStatus = p2.SignUpStatus;
            result.Id = p2.Id;
            result.Email = p2.Email;
            result.PhoneNumber = p2.PhoneNumber;
            return result;
            
        }
        public static ApplicationUserSDto AdaptToSDto(this ApplicationUser p4)
        {
            return p4 == null ? null : new ApplicationUserSDto()
            {
                PhoneNumber = p4.PhoneNumber,
                FirstName = p4.FirstName,
                LastName = p4.LastName,
                BirthDate = p4.BirthDate,
                Gender = p4.Gender,
                SignUpStatus = p4.SignUpStatus,
                NationalId = p4.NationalId,
                Email = p4.Email,
                Id = p4.Id
            };
        }
        public static ApplicationUserSDto AdaptTo(this ApplicationUser p5, ApplicationUserSDto p6)
        {
            if (p5 == null)
            {
                return null;
            }
            ApplicationUserSDto result = p6 ?? new ApplicationUserSDto();
            
            result.PhoneNumber = p5.PhoneNumber;
            result.FirstName = p5.FirstName;
            result.LastName = p5.LastName;
            result.BirthDate = p5.BirthDate;
            result.Gender = p5.Gender;
            result.SignUpStatus = p5.SignUpStatus;
            result.NationalId = p5.NationalId;
            result.Email = p5.Email;
            result.Id = p5.Id;
            return result;
            
        }
        public static Expression<Func<ApplicationUser, ApplicationUserSDto>> ProjectToSDto => p7 => new ApplicationUserSDto()
        {
            PhoneNumber = p7.PhoneNumber,
            FirstName = p7.FirstName,
            LastName = p7.LastName,
            BirthDate = p7.BirthDate,
            Gender = p7.Gender,
            SignUpStatus = p7.SignUpStatus,
            NationalId = p7.NationalId,
            Email = p7.Email,
            Id = p7.Id
        };
    }
}