import * as plugins from './plugins.js';

@plugins.smartdata.Manager()
export class BusinessRecord extends plugins.smartdata.SmartDataDbDoc<
  BusinessRecord,
  BusinessRecord
> {
  // STATIC
  public static getByGermanParsedRegistration = async (parsedGermanRegistrationArg: BusinessRecord['data']['germanParsedRegistration']) => {
    const businessRecords = await BusinessRecord.getInstance({
      data: {
        germanParsedRegistration: parsedGermanRegistrationArg,
      }
    });
    return businessRecords;
  };


  // INSTANCE
  @plugins.smartdata.unI()
  id: string;

  @plugins.smartdata.svDb()
  data: {
    name?: string;
    startDate?: string;
    endDate?: string;
    status?: 'active' | 'liquidating' | 'closed';
    address?: string;
    postalCode?: string;
    city?: string;
    country?: string;
    phone?: string;
    fax?: string;
    email?: string;
    website?: string;
    businessType?: string;
    registrationId?: string;
    germanParsedRegistration?: {
      court?: string;
      type?: 'HRA' | 'HRB' | 'GnR' | 'PR' | 'VR' | 'GsR';
      number?: string;
    };
    legalForm?:
      | 'GmbH'
      | 'GmbH & Co. KG'
      | 'AG'
      | 'LLC'
      | 'LLP'
      | 'GmbH & Co. KGaA'
      | 'GmbH & Co. KGaA, LLC';
    managingDirectors?: string[];
    boardOfDirectors?: string[];
    supervisoryBoard?: string[];
    foundingDate?: string;
    capital?: string;
    purpose?: string;
    lastUpdate?: string;
  } = {};

  /**
   * validates the record against the Handelregister.
   */
  public async validate() {
    if (!this.data.name) throw new Error('Name is required.');
  }
}