package com.social.media.application.company.query;

import com.social.media.domain.shared.enums.CompanyStatus;

/**
 * Query to list companies with filtering options.
 * Follows Query pattern for CQRS implementation.
 */
public record ListCompaniesQuery(
    CompanyStatus status,
    String plan,
    String activitySector,
    int page,
    int size,
    String sortBy,
    String sortDirection
) {
    
    public ListCompaniesQuery {
        if (page < 0) {
            throw new IllegalArgumentException("Page cannot be negative");
        }
        
        if (size <= 0) {
            throw new IllegalArgumentException("Size must be positive");
        }
        
        if (size > 100) {
            throw new IllegalArgumentException("Size cannot exceed 100");
        }
    }
    
    /**
     * Creates a default query with no filters
     */
    public static ListCompaniesQuery defaultQuery() {
        return new ListCompaniesQuery(
            null, // no status filter
            null, // no plan filter
            null, // no activity sector filter
            0,    // first page
            20,   // default page size
            "createdAt", // sort by creation date
            "DESC" // newest first
        );
    }
    
    /**
     * Creates a query for active companies only
     */
    public static ListCompaniesQuery activeCompanies() {
        return new ListCompaniesQuery(
            CompanyStatus.ACTIVE,
            null,
            null,
            0,
            20,
            "companyName",
            "ASC"
        );
    }
}

