using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
using AyCode.Interfaces.Addresses;
using AyCode.Interfaces.Addresses.Dtos;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.Profiles.Dtos;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.TimeStampInfo;
using AyCode.Interfaces.Users;
using AyCode.Interfaces.Users.Dtos;

namespace AyCode.Models.Users;

//public abstract class AcUserModelDtoDetailBase<TUserDtoDetail, TProfile, TCompany, TUserToCompany, TAddressDto> : AcUserModelDtoDetailBase<TUserDtoDetail, TProfile, TProfile, TCompany, TUserToCompany, TAddressDto>
//    where TUserDtoDetail : class, IAcUserDtoDetailBase
//    where TProfile: class, IAcProfile<TAddressDto>
//    where TCompany : class, IAcCompanyBase
//    where TUserToCompany : class, IAcUserToCompanyBase
//    where TAddressDto : class, IAcAddressDtoBase
//{
//    protected AcUserModelDtoDetailBase() : base()
//    {}

//    protected AcUserModelDtoDetailBase(IAcUserDtoDetailBase<TProfile, TCompany, TUserToCompany, TAddressDto> user) : base(user)
//    {
//    }
//}

public abstract class AcUserModelDtoDetailBase<TUserDtoDetail, TProfileDto, TCompany, TUserToCompany, TAddressDto> : AcUserModelDtoBase<TUserDtoDetail, TProfileDto, TCompany, TUserToCompany> 
    where TUserDtoDetail : class, IAcUserDtoDetailBase
    where TProfileDto : class, IAcProfileDtoBase<TAddressDto>
    where TCompany : class, IAcCompanyBase
    where TUserToCompany : class, IAcUserToCompanyBase
    where TAddressDto : class, IAcAddressDtoBase
{
    //public TAddressDto AddressDto { get; set; }

    protected AcUserModelDtoDetailBase() : base() {}

    protected AcUserModelDtoDetailBase(IAcUserDtoDetailBase<TProfileDto, TCompany, TUserToCompany, TAddressDto> user) : base(user)
    {
        UserDto.Id = user.Id;
        UserDto.ProfileId = user.ProfileId;
        UserDto.EmailAddress = user.EmailAddress;
        UserDto.EmailConfirmed = user.EmailConfirmed;
        UserDto.PhoneNumber = user.PhoneNumber;
        UserDto.RefferalId = user.RefferalId;
        UserDto.AffiliateId = user.AffiliateId;
        UserDto.RefreshToken = user.RefreshToken;
        UserDto.Created = user.Created;
        UserDto.Modified = user.Modified;
        
        var address = Activator.CreateInstance<TAddressDto>();
        
        address.Id = user.Profile.AddressId;
        address.AddressText = user.Profile.Address.AddressText;
        address.Latitude = user.Profile.Address.Latitude;
        address.Longitude = user.Profile.Address.Longitude;

        ProfileDto.Address = address;
    }

    public void CopyUserDtoValuesToUser(IAcUserDtoDetailBase<TProfileDto, TCompany, TUserToCompany, TAddressDto> user)
    {
        base.CopyUserDtoValuesToUser(user);

        user.ProfileId = UserDto.ProfileId;
        user.EmailAddress = UserDto.EmailAddress;
        user.EmailConfirmed = UserDto.EmailConfirmed;
        user.PhoneNumber = UserDto.PhoneNumber;
        user.RefferalId = UserDto.RefferalId;
        //user.RefreshToken = UserDto.RefreshToken; //Ezzel mi legyen?! - J.
        user.Created = UserDto.Created;
        user.Modified = UserDto.Modified;
    }
}