import {
  createEmploye,
  deleteEmployeByCos,
  getEmployeByCos,
  listEmployes,
  updateEmployeByCos,
  type EmployeeAccessScope,
} from "@/services/employes.service";
import { omitInternalId, omitInternalIdList } from "@/server/public-entity";
import type { PublicEmploye, PublicFeed } from "@/types";
import type {
  EmployeCreateInput,
  EmployeUpdateInput,
} from "@/validators/employes";

export async function getEmployesFeed(
  limit: number,
  offset: number,
  scope: EmployeeAccessScope,
): Promise<PublicFeed<PublicEmploye>> {
  const employes = await listEmployes(limit, offset, scope);

  return {
    items: omitInternalIdList(employes),
    count: employes.length,
  };
}

export async function getEmployeDetails(
  cos: number,
  scope?: EmployeeAccessScope,
): Promise<{ employe: PublicEmploye | null | undefined }> {
  const employe = await getEmployeByCos(cos, scope);

  return {
    employe: omitInternalId(employe),
  };
}

export async function createEmployeFeed(
  data: EmployeCreateInput,
): Promise<{ employe: PublicEmploye | null | undefined }> {
  const employe = await createEmploye(data);

  return {
    employe: omitInternalId(employe),
  };
}

export async function updateEmployeFeed(
  cos: number,
  data: EmployeUpdateInput,
): Promise<{ employe: PublicEmploye | null | undefined }> {
  const employe = await updateEmployeByCos(cos, data);

  return {
    employe: omitInternalId(employe),
  };
}

export async function deleteEmployeFeed(
  cos: number,
): Promise<{ employe: PublicEmploye | null | undefined }> {
  const employe = await deleteEmployeByCos(cos);

  return {
    employe: omitInternalId(employe),
  };
}
