package com.spring.domain.user.dto;

import com.spring.domain.user.entity.AgentUser;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class UserFindRequest {
    
    private final String userId;
    private final String userName;
    private final String email;
    private final String approved;

    public static boolean matchesCriteria(AgentUser user, UserFindRequest request) {
        return matchesUserId(user, request.getUserId()) &&
                matchesUserName(user, request.getUserName()) &&
                matchesEmail(user, request.getEmail()) &&
                matchesApprovedCriteria(request.getApproved(), user.isApproved());
    }
    
    public static boolean matchesUserId(AgentUser user, String userId) {
        return userId == null || userId.isEmpty() || user.getUserId().contains(userId);
    }
    
    public static boolean matchesUserName(AgentUser user, String userName) {
        return userName == null || userName.isEmpty() || user.getName().contains(userName);
    }
    
    public static boolean matchesEmail(AgentUser user, String email) {
        return email == null || email.isEmpty() || user.getEmail().contains(email);
    }
    
    public static boolean matchesApprovedCriteria(String approved, boolean userApproved) {
        return "all".equals(approved) || 
                ("true".equals(approved) && userApproved) || 
                ("false".equals(approved) && !userApproved);
    }

}
