import { request } from './index';
import { UserType } from './user';

export type CodeType = {
  id: number;
  text: string;
  share: number;
  discount: number;
  validDays: number;
  sharePrice: number;
  studentCount: number;
};

export type IntroducerType = {
  id: number;
  user: UserType;
  iban: string;
  sharePrice: number;
  paidPrice: number;
  studentCount: number;
  code: CodeType;
};

export async function fetchIntroducer(): Promise<IntroducerType> {
  return await request(true, { url: '/introducers/introducer' });
}

export type CreateIntroducerDataType = { iban: string };

export async function createIntroducer(data: CreateIntroducerDataType): Promise<IntroducerType> {
  return await request(true, {
    url: '/introducers/introducers',
    method: 'POST',
    data
  });
}

export type UpdateIntroducerDataType = { iban: string };

export async function updateIntroducer(data: UpdateIntroducerDataType): Promise<IntroducerType> {
  return await request(true, {
    url: '/introducers/introducer',
    method: 'PATCH',
    data
  });
}
