import { finance, general } from "../index.js";
import { business } from "../index.js";

export type TSocialLinks = {
  type: "facebook" | "twitter" | "linkedin" | string;
  url: string;
};

export type TRegistrationDetails = {
  vatId: string;
  registrationId: string;
  registrationName: string;
};

type TContactEnvelope<TYPE extends string, FIELDS> = {
  type: TYPE;
  name: string;
  address: business.IAddress;
  description: string;
  legalEntity?: string;
  customerNumber?: string;
  relationship?: "customer" | "supplier" | "partner" | "employee" | "other";

  email?: string;
  phone?: string;
  fax?: string;

  logoUrl?: string;
  website?: string;

  socials?: TSocialLinks[];

  sepaConnection?: finance.ISepaConnection;
} & FIELDS;

export type TPerson = TContactEnvelope<
  "person",
  {
    surname: string;
    salutation: "Mr" | "Ms" | "Mrs";
    sex: "male" | "female" | "other";
    title: "Doctor" | "Professor";
    registrationDetails?: TRegistrationDetails;
    legalProxyFor?: {
      type: "self" | "other";
      contact?: TContact;
    };
  }
>;

type TCompanyInCreation = {
  status: "planned" | "founding";
};

type TCompanyActive = {
  status: "active";
  foundedDate: general.IDate;
};

type TCompanyInLiquidation = {
  status: "liquidation";
  foundedDate: general.IDate;
  liquidationDate: general.IDate;
};

type TCompanyClosed = {
  status: "closed";
  foundedDate: general.IDate;
  liquidationDate: general.IDate;
  closedDate: general.IDate;
};

type TCompanyStatus =
  | TCompanyInCreation
  | TCompanyActive
  | TCompanyInLiquidation
  | TCompanyClosed;

export type TCompany = TContactEnvelope<
  "company",
  { registrationDetails: TRegistrationDetails } & TCompanyStatus
>;

export type TContact = TPerson | TCompany;
