using System;
using System.Linq.Expressions;
using Brizco.Domain.Dtos.SmallDtos;
using Brizco.Domain.Entities.Complexes;
using Brizco.Domain.Entities.Users;
using Mapster.Models;

namespace Brizco.Domain.Mappers
{
    public static partial class ComplexUserMapper
    {
        public static ComplexUser AdaptToComplexUser(this ComplexUserSDto p1)
        {
            return p1 == null ? null : new ComplexUser()
            {
                UserId = p1.UserId,
                ComplexId = p1.ComplexId,
                User = new ApplicationUser() {Id = p1.UserId},
                Complex = new Complex()
                {
                    Name = p1.ComplexName,
                    Id = p1.ComplexId
                },
                Id = p1.Id
            };
        }
        public static ComplexUser AdaptTo(this ComplexUserSDto p2, ComplexUser p3)
        {
            if (p2 == null)
            {
                return null;
            }
            ComplexUser result = p3 ?? new ComplexUser();
            
            result.UserId = p2.UserId;
            result.ComplexId = p2.ComplexId;
            result.User = funcMain1(new Never(), result.User, p2);
            result.Complex = funcMain2(new Never(), result.Complex, p2);
            result.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<ComplexUserSDto, ComplexUser>> ProjectToComplexUser => p8 => new ComplexUser()
        {
            UserId = p8.UserId,
            ComplexId = p8.ComplexId,
            User = new ApplicationUser() {Id = p8.UserId},
            Complex = new Complex()
            {
                Name = p8.ComplexName,
                Id = p8.ComplexId
            },
            Id = p8.Id
        };
        public static ComplexUserSDto AdaptToSDto(this ComplexUser p9)
        {
            return p9 == null ? null : new ComplexUserSDto()
            {
                FirstName = p9.User != null ? p9.User.FirstName : string.Empty,
                LastName = p9.User != null ? p9.User.LastName : string.Empty,
                NationalId = p9.User != null ? p9.User.NationalId : string.Empty,
                ComplexName = p9.Complex != null ? p9.Complex.Name : string.Empty,
                UserId = p9.UserId,
                ComplexId = p9.ComplexId,
                Id = p9.Id
            };
        }
        public static ComplexUserSDto AdaptTo(this ComplexUser p10, ComplexUserSDto p11)
        {
            if (p10 == null)
            {
                return null;
            }
            ComplexUserSDto result = p11 ?? new ComplexUserSDto();
            
            result.FirstName = p10.User != null ? p10.User.FirstName : string.Empty;
            result.LastName = p10.User != null ? p10.User.LastName : string.Empty;
            result.NationalId = p10.User != null ? p10.User.NationalId : string.Empty;
            result.ComplexName = p10.Complex != null ? p10.Complex.Name : string.Empty;
            result.UserId = p10.UserId;
            result.ComplexId = p10.ComplexId;
            result.Id = p10.Id;
            return result;
            
        }
        public static Expression<Func<ComplexUser, ComplexUserSDto>> ProjectToSDto => p12 => new ComplexUserSDto()
        {
            FirstName = p12.User != null ? p12.User.FirstName : string.Empty,
            LastName = p12.User != null ? p12.User.LastName : string.Empty,
            NationalId = p12.User != null ? p12.User.NationalId : string.Empty,
            ComplexName = p12.Complex != null ? p12.Complex.Name : string.Empty,
            UserId = p12.UserId,
            ComplexId = p12.ComplexId,
            Id = p12.Id
        };
        
        private static ApplicationUser funcMain1(Never p4, ApplicationUser p5, ComplexUserSDto p2)
        {
            ApplicationUser result = p5 ?? new ApplicationUser();
            
            result.Id = p2.UserId;
            return result;
            
        }
        
        private static Complex funcMain2(Never p6, Complex p7, ComplexUserSDto p2)
        {
            Complex result = p7 ?? new Complex();
            
            result.Name = p2.ComplexName;
            result.Id = p2.ComplexId;
            return result;
            
        }
    }
}