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 ComplexUserRoleMapper
    {
        public static ComplexUserRole AdaptToComplexUserRole(this ComplexUserRoleSDto p1)
        {
            return p1 == null ? null : new ComplexUserRole()
            {
                ComplexUserId = p1.ComplexUserId,
                ComplexUser = new ComplexUser() {Id = p1.ComplexUserId},
                RoleId = p1.RoleId,
                Role = new ApplicationRole()
                {
                    Id = p1.RoleId,
                    Name = p1.RoleName
                },
                Id = p1.Id
            };
        }
        public static ComplexUserRole AdaptTo(this ComplexUserRoleSDto p2, ComplexUserRole p3)
        {
            if (p2 == null)
            {
                return null;
            }
            ComplexUserRole result = p3 ?? new ComplexUserRole();
            
            result.ComplexUserId = p2.ComplexUserId;
            result.ComplexUser = funcMain1(new Never(), result.ComplexUser, p2);
            result.RoleId = p2.RoleId;
            result.Role = funcMain2(new Never(), result.Role, p2);
            result.Id = p2.Id;
            return result;
            
        }
        public static Expression<Func<ComplexUserRoleSDto, ComplexUserRole>> ProjectToComplexUserRole => p8 => new ComplexUserRole()
        {
            ComplexUserId = p8.ComplexUserId,
            ComplexUser = new ComplexUser() {Id = p8.ComplexUserId},
            RoleId = p8.RoleId,
            Role = new ApplicationRole()
            {
                Id = p8.RoleId,
                Name = p8.RoleName
            },
            Id = p8.Id
        };
        public static ComplexUserRoleSDto AdaptToSDto(this ComplexUserRole p9)
        {
            return p9 == null ? null : new ComplexUserRoleSDto()
            {
                RoleId = p9.RoleId,
                ComplexUserId = p9.ComplexUserId,
                RoleName = p9.Role == null ? null : p9.Role.PersianName,
                Id = p9.Id
            };
        }
        public static ComplexUserRoleSDto AdaptTo(this ComplexUserRole p10, ComplexUserRoleSDto p11)
        {
            if (p10 == null)
            {
                return null;
            }
            ComplexUserRoleSDto result = p11 ?? new ComplexUserRoleSDto();
            
            result.RoleId = p10.RoleId;
            result.ComplexUserId = p10.ComplexUserId;
            result.RoleName = p10.Role == null ? null : p10.Role.PersianName;
            result.Id = p10.Id;
            return result;
            
        }
        public static Expression<Func<ComplexUserRole, ComplexUserRoleSDto>> ProjectToSDto => p12 => new ComplexUserRoleSDto()
        {
            RoleId = p12.RoleId,
            ComplexUserId = p12.ComplexUserId,
            RoleName = p12.Role.PersianName,
            Id = p12.Id
        };
        
        private static ComplexUser funcMain1(Never p4, ComplexUser p5, ComplexUserRoleSDto p2)
        {
            ComplexUser result = p5 ?? new ComplexUser();
            
            result.Id = p2.ComplexUserId;
            return result;
            
        }
        
        private static ApplicationRole funcMain2(Never p6, ApplicationRole p7, ComplexUserRoleSDto p2)
        {
            ApplicationRole result = p7 ?? new ApplicationRole();
            
            result.Id = p2.RoleId;
            result.Name = p2.RoleName;
            return result;
            
        }
    }
}