using Marco.Pms.Model.Dtos.Employees;
using Marco.Pms.Model.Employees;
using Marco.Pms.Model.ViewModels.Activities;
using Marco.Pms.Model.ViewModels.Employee;

namespace Marco.Pms.Model.Mapper
{
    public static class EmployeeMapper
    {
        public static EmployeeVM ToEmployeeVMFromEmployee(this Employee model)
        {
            string? base64String = null;
            if ((model.Photo != null))
            {
                base64String = Convert.ToBase64String(model.Photo);
            }
            return new EmployeeVM
            {
                Id = model.Id,
                FirstName = model.FirstName,
                LastName = model.LastName,
                MiddleName = model.MiddleName,
                Email = model.Email,
                CurrentAddress = model.CurrentAddress,
                BirthDate = model.BirthDate,
                ApplicationUserId = model.ApplicationUserId,
                EmergencyPhoneNumber = model.EmergencyPhoneNumber,
                EmergencyContactPerson = model.EmergencyContactPerson,
                Gender = model.Gender,
                JobRole = (model.JobRole != null ? model.JobRole.Name : null),
                JobRoleId = model.JobRoleId,
                PermanentAddress = model.PermanentAddress,
                PhoneNumber = model.PhoneNumber,
                Photo = base64String,
                IsActive = model.IsActive,
                IsRootUser = model.ApplicationUser?.IsRootUser ?? false,
                IsSystem = model.IsSystem,
                JoiningDate = model.JoiningDate,
                TenantId = model.TenantId ?? Guid.Empty,
                HasApplicationAccess = model.HasApplicationAccess,
                OrganizationId = model.OrganizationId
            };
        }
        public static BasicEmployeeVM ToBasicEmployeeVMFromEmployee(this Employee employee)
        {
            return new BasicEmployeeVM
            {
                Id = employee.Id,
                FirstName = employee.FirstName,
                LastName = employee.LastName,
                Photo = employee.Photo,
                JobRoleId = employee.JobRoleId,
                JobRoleName = employee.JobRole != null ? employee.JobRole.Name : ""
            };
        }
        public static Employee ToEmployeeFromMobileUserManageDto(this MobileUserManageDto model, Guid TenantId, byte[]? image)
        {
            return new Employee
            {
                ApplicationUserId = null,
                FirstName = model.FirstName,
                LastName = model.LastName,
                Email = string.Empty,
                TenantId = TenantId,
                CurrentAddress = string.Empty,
                BirthDate = null,
                EmergencyPhoneNumber = string.Empty,
                EmergencyContactPerson = string.Empty,
                Gender = model.Gender,
                MiddleName = string.Empty,
                PermanentAddress = string.Empty,
                PhoneNumber = model.PhoneNumber,
                Photo = image,
                JobRoleId = model.JobRoleId,
                JoiningDate = model.JoiningDate,

            };
        }
    }
}
