const formatServiceUrl = (url: string) => {
  if (!url) return "";
  return url.startsWith("http") ? url : `http://${url}`;
};

export const baseUrlAuth = formatServiceUrl(
  process.env.NEXT_PUBLIC_AUTH_SERVICE_URL || "auth_service:8001"
);
// export const baseUrlValidation = formatServiceUrl(
//   process.env.NEXT_PUBLIC_VALIDATION_SERVICE_URL || "validationservice:8888"
// );
// export const baseUrlEvent = formatServiceUrl(
//   process.env.NEXT_PUBLIC_EVENT_SERVICE_URL || "eventservice:8888"
// );
export const tokenSecret = process.env.TOKENSECRET_90 || "";

export const cookieObject: any = {
  httpOnly: true,
  path: "/",
  sameSite: "none",
  secure: true,
  maxAge: 3600,
  priority: "high",
};

interface FilterListInterface {
  page?: number | null | undefined;
  size?: number | null | undefined;
  orderField?: string | null | undefined;
  orderType?: string | null | undefined;
  includeJoins?: any[] | null | undefined;
  query?: any | null | undefined;
}

class FilterList {
  page: number;
  size: number;
  orderField: string;
  orderType: string;
  includeJoins: any[];
  query: any;

  constructor({
    page = 1,
    size = 5,
    orderField = "id",
    orderType = "asc",
    includeJoins = [],
    query = {},
  }: FilterListInterface = {}) {
    this.page = page ?? 1;
    this.size = size ?? 5;
    this.orderField = orderField ?? "uu_id";
    this.orderType = orderType ?? "asc";
    this.orderType = this.orderType.startsWith("a") ? "asc" : "desc";
    this.includeJoins = includeJoins ?? [];
    this.query = query ?? {};
  }

  filter() {
    return {
      page: this.page,
      size: this.size,
      orderField: this.orderField,
      orderType: this.orderType,
      includeJoins: this.includeJoins,
      query: this.query,
    };
  }
}

const defaultFilterList = new FilterList({});

export { FilterList, defaultFilterList };
export type { FilterListInterface };
