import { v4 } from "uuid";
import { createPartnerAccessToken } from "../access-token/index.js";
import { getPartnerStore } from "./store.js";
import { addOrganisation } from "../organisation/index.js";
export async function addPartner(data) {
    const store = getPartnerStore();
    const partnerId = v4();
    const { partnerName, ...organisationData } = data;
    const { organisationId } = await addOrganisation({
        ...organisationData,
        organisationName: partnerName,
        partnerId,
    });
    const createdAt = new Date().toISOString();
    const partner = {
        partnerName,
        partnerId,
        organisationId,
        approved: false,
        approvedAt: undefined,
        approvedByUserId: undefined,
        createdAt,
        updatedAt: createdAt,
    };
    await store.set(partnerId, partner);
    const { accessToken } = await createPartnerAccessToken(partnerId);
    return {
        ...partner,
        accessToken,
    };
}
//# sourceMappingURL=add-partner.js.map