import type { DB } from "../generated/kysely-tailordb";
import type { PartnerRoleRole } from "../generated/enums";
import { ok, type ReadonlyDB } from "@tailor-platform/erp-kit/module";

export interface GetPartnerRoleInput {
  partnerId: string;
  role: string;
}

export async function run(db: ReadonlyDB<DB>, input: GetPartnerRoleInput) {
  const partnerRole = await db
    .selectFrom("PartnerRole")
    .selectAll()
    .where("partnerId", "=", input.partnerId)
    .where("role", "=", input.role as PartnerRoleRole)
    .executeTakeFirst();

  return ok({ partnerRole: partnerRole ?? null });
}
