package pl.polskalokalnie.auth.dto;

import java.time.Instant;
import java.time.LocalDate;
import pl.polskalokalnie.user.AccountType;
import pl.polskalokalnie.user.AppUser;
import pl.polskalokalnie.user.AuthProvider;
import pl.polskalokalnie.user.ContactPreference;
import pl.polskalokalnie.user.PreferredLanguage;
import pl.polskalokalnie.user.Role;

public record UserResponse(
        Long id,
        String email,
        String fullName,
        Role role,
        AuthProvider provider,
        AccountType accountType,
        String phone,
        String address,
        ContactPreference contactPreference,
        PreferredLanguage preferredLanguage,
        String nip,
        LocalDate birthDate,
        boolean verified,
        boolean blocked,
        Instant createdAt
) {
    public static UserResponse from(AppUser user) {
        return new UserResponse(
                user.getId(),
                user.getEmail(),
                user.getFullName(),
                user.getRole(),
                user.getProvider(),
                user.getAccountType(),
                user.getPhone(),
                user.getAddress(),
                user.getContactPreference() != null ? user.getContactPreference() : ContactPreference.EMAIL_AND_PHONE,
                user.getPreferredLanguage() != null ? user.getPreferredLanguage() : PreferredLanguage.PL,
                user.getNip(),
                user.getBirthDate(),
                user.isVerified(),
                user.isBlocked(),
                user.getCreatedAt()
        );
    }
}
