import { IAdapter, RepositoryBuilder } from "@/contexts/common/domain";
import { Dealer, IDealerRepository } from "@/contexts/sales/domain";
import { UniqueID } from "@shared/contexts";

export const existsDealerByID = async (
  id: UniqueID,
  adapter: IAdapter,
  repository: RepositoryBuilder<IDealerRepository>
): Promise<boolean> => {
  return await adapter
    .startTransaction()
    .complete(async (t) => repository({ transaction: t }).exists(id));
};

export const findDealerByID = async (
  id: UniqueID,
  adapter: IAdapter,
  repository: RepositoryBuilder<IDealerRepository>
): Promise<Dealer | null> => {
  return await adapter
    .startTransaction()
    .complete(async (t) => repository({ transaction: t }).getById(id));
};
