using System;
using System.Linq.Expressions;
using Netina.Domain.Dtos.SmallDtos;
using Netina.Domain.Entities.Users;
using Netina.Domain.Enums;

namespace Netina.Domain.Mappers
{
    public static partial class MarketerMapper
    {
        public static Marketer AdaptToMarketer(this MarketerSDto p1)
        {
            return p1 == null ? null : new Marketer()
            {
                FatherName = p1.FatherName,
                Shaba = p1.Shaba,
                Id = p1.Id,
                CreatedAt = p1.CreatedAt
            };
        }
        public static Marketer AdaptTo(this MarketerSDto p2, Marketer p3)
        {
            if (p2 == null)
            {
                return null;
            }
            Marketer result = p3 ?? new Marketer();
            
            result.FatherName = p2.FatherName;
            result.Shaba = p2.Shaba;
            result.Id = p2.Id;
            result.CreatedAt = p2.CreatedAt;
            return result;
            
        }
        public static MarketerSDto AdaptToSDto(this Marketer p4)
        {
            return p4 == null ? null : new MarketerSDto()
            {
                PhoneNumber = p4.User != null ? p4.User.PhoneNumber : string.Empty,
                FirstName = p4.User != null ? p4.User.FirstName : string.Empty,
                LastName = p4.User != null ? p4.User.LastName : string.Empty,
                BirthDate = p4.User != null ? p4.User.BirthDate : DateTime.MinValue,
                Gender = p4.User != null ? p4.User.Gender : Gender.Male,
                SignUpStatus = p4.User != null ? p4.User.SignUpStatus : SignUpStatus.StartSignOn,
                NationalId = p4.User != null ? p4.User.NationalId : string.Empty,
                Email = p4.User != null ? p4.User.Email : string.Empty,
                FatherName = p4.FatherName,
                Shaba = p4.Shaba,
                Id = p4.Id,
                CreatedAt = p4.CreatedAt
            };
        }
        public static MarketerSDto AdaptTo(this Marketer p5, MarketerSDto p6)
        {
            if (p5 == null)
            {
                return null;
            }
            MarketerSDto result = p6 ?? new MarketerSDto();
            
            result.PhoneNumber = p5.User != null ? p5.User.PhoneNumber : string.Empty;
            result.FirstName = p5.User != null ? p5.User.FirstName : string.Empty;
            result.LastName = p5.User != null ? p5.User.LastName : string.Empty;
            result.BirthDate = p5.User != null ? p5.User.BirthDate : DateTime.MinValue;
            result.Gender = p5.User != null ? p5.User.Gender : Gender.Male;
            result.SignUpStatus = p5.User != null ? p5.User.SignUpStatus : SignUpStatus.StartSignOn;
            result.NationalId = p5.User != null ? p5.User.NationalId : string.Empty;
            result.Email = p5.User != null ? p5.User.Email : string.Empty;
            result.FatherName = p5.FatherName;
            result.Shaba = p5.Shaba;
            result.Id = p5.Id;
            result.CreatedAt = p5.CreatedAt;
            return result;
            
        }
        public static Expression<Func<Marketer, MarketerSDto>> ProjectToSDto => p7 => new MarketerSDto()
        {
            PhoneNumber = p7.User != null ? p7.User.PhoneNumber : string.Empty,
            FirstName = p7.User != null ? p7.User.FirstName : string.Empty,
            LastName = p7.User != null ? p7.User.LastName : string.Empty,
            BirthDate = p7.User != null ? p7.User.BirthDate : DateTime.MinValue,
            Gender = p7.User != null ? p7.User.Gender : Gender.Male,
            SignUpStatus = p7.User != null ? p7.User.SignUpStatus : SignUpStatus.StartSignOn,
            NationalId = p7.User != null ? p7.User.NationalId : string.Empty,
            Email = p7.User != null ? p7.User.Email : string.Empty,
            FatherName = p7.FatherName,
            Shaba = p7.Shaba,
            Id = p7.Id,
            CreatedAt = p7.CreatedAt
        };
    }
}