export interface Company {
  id: number;
  identifier: string;
  name: string;
  status: CompanyStatus;
  addressLine1: string;
  addressLine2?: string;
  city: string;
  state: string;
  zip: string;
  country: BasicEntity;
  phoneNumber: string;
  faxNumber: string;
  website: string;
  territory: Territory;
  market: Market;
  accountNumber: string;
  defaultContact: ContactHref;
  dateAcquired: string;
  annualRevenue: number;
  numberOfEmployees: number;
  leadFlag: boolean;
  unsubscribeFlag: boolean;
  vendorIdentifier: string;
  taxIdentifier: string;
  taxCode: TaxCode;
  billingTerms: BasicEntity;
  billToCompany: LinkedCompany;
  billingSite: LinkedSite;
  billingContact: ContactHref;
  invoiceDeliveryMethod: BasicEntity;
  invoiceToEmailAddress: string;
  deletedFlag: boolean;
  dateDeleted: string;
  mobileGuid: string;
  resellerIdentifier: string;
  isVendorFlag: boolean;
  types: TypeItem[];
  site: LinkedSite;
  _info: CompanyInfo;
  customFields: CustomField[];
}

export interface CompanyStatus {
  id: number;
  name: string;
  _info: {
    status_href: string;
  };
}

export interface Territory {
  id: number;
  name: string;
  _info: {
    location_href: string;
  };
}

export interface Market {
  id: number;
  name: string;
  _info: {
    Market_href: string;
  };
}

export interface TaxCode {
  id: number;
  name: string;
  _info: {
    taxCode_href: string;
  };
}

export interface BasicEntity {
  id: number;
  name: string;
}

export interface LinkedCompany extends BasicEntity {
  identifier: string;
  _info: {
    company_href: string;
  };
}

export interface LinkedSite extends BasicEntity {
  _info: {
    site_href: string;
  };
}

export interface ContactHref {
  id: number;
  name: string;
  _info: {
    contact_href: string;
  };
}

export interface TypeItem {
  id: number;
  name: string;
  _info: {
    type_href: string;
  };
}

export interface CompanyInfo {
  lastUpdated: string;
  updatedBy: string;
  dateEntered: string;
  enteredBy: string;
  contacts_href: string;
  agreements_href: string;
  tickets_href: string;
  opportunities_href: string;
  activities_href: string;
  projects_href: string;
  configurations_href: string;
  orders_href: string;
  documents_href: string;
  sites_href: string;
  teams_href: string;
  reports_href: string;
  notes_href: string;
}

export interface CustomField {
  id: number;
  caption: string;
  type: string;
  entryMethod: string;
  numberOfDecimals: number;
  value: string | null;
  connectWiseId: string;
  rowNum: number;
  userDefinedFieldRecId: number;
  podId: string;
}

/**
 *
 * CONFIGURATION INTERFACES
 *
 */

export interface ConfigurationItem {
  id: number;
  name: string;

  type: ConfigurationTypeRef;
  status: ConfigurationStatusRef;

  company: CompanyRef;
  contact: ContactRef;
  site: SiteRef;

  locationId: number;
  location: LocationRef;

  businessUnitId: number;
  department: DepartmentRef;

  deviceIdentifier: string;
  serialNumber: string;
  modelNumber: string;
  tagNumber: string;

  installationDate: string; // ISO-8601
  warrantyExpirationDate?: string; // ISO-8601 (only present on some items)

  installedBy?: MemberRef; // only present on some items

  vendorNotes: string;
  notes: string;

  macAddress: string;
  lastLoginName: string;

  billFlag: boolean;

  backupSuccesses: number;
  backupIncomplete: number;
  backupFailed: number;
  backupRestores: number;
  backupServerName: string;
  backupBillableSpaceGb: number;
  backupProtectedDeviceList: string;
  backupYear: number;
  backupMonth: number;

  ipAddress: string;
  defaultGateway: string;

  osType: string;
  osInfo: string;
  cpuSpeed: string;
  ram: string;
  localHardDrives: string;

  questions: ConfigurationQuestion[];

  activeFlag: boolean;
  mobileGuid: string;

  companyLocationId: number;
  showRemoteFlag: boolean;
  showAutomateFlag: boolean;
  needsRenewalFlag: boolean;

  manufacturerPartNumber?: string; // only present on some items

  _info: ConfigurationInfo;
}

export interface ConfigurationTypeRef {
  id: number;
  name: string;
  _info: {
    type_href: string;
  };
}

export interface ConfigurationStatusRef {
  id: number;
  name: string;
  _info: {
    status_href: string;
  };
}

export interface CompanyRef {
  id: number;
  identifier: string;
  name: string;
  _info: {
    company_href: string;
  };
}

export interface ContactRef {
  id: number;
  name: string;
  _info: {
    contact_href: string;
  };
}

export interface SiteRef {
  id: number;
  name: string;
  _info: {
    site_href: string;
  };
}

export interface LocationRef {
  id: number;
  name: string;
  _info: {
    location_href: string;
  };
}

export interface DepartmentRef {
  id: number;
  identifier: string;
  name: string;
  _info: {
    department_href: string;
  };
}

export interface MemberRef {
  id: number;
  identifier: string;
  name: string;
  _info: {
    member_href: string;
  };
}

export interface ConfigurationQuestion {
  answerId: number;
  questionId: number;
  question: string;

  answer?: string | boolean; // absent on some, boolean for Checkbox in your sample

  sequenceNumber: number;
  numberOfDecimals: number;

  fieldType: "Text" | "TextArea" | "Password" | "Date" | "Checkbox" | string;
  requiredFlag: boolean;
}

export interface ConfigurationInfo {
  lastUpdated: string; // ISO-8601
  updatedBy: string;
  dateEntered: string; // ISO-8601
  enteredBy: string;
}

// Your payload is an array:
export type ConfigurationResponse = ConfigurationItem[];
export interface Contact {
  id: number;
  firstName: string;
  lastName: string;
  company: ContactCompany;
  site: ContactSite;
  relationship: ContactRelationship;
  department: ContactDepartment;
  inactiveFlag: boolean;
  title: string;
  marriedFlag: boolean;
  childrenFlag: boolean;
  disablePortalLoginFlag: boolean;
  unsubscribeFlag: boolean;
  mobileGuid: string;
  facebookUrl: string;
  twitterUrl: string;
  linkedInUrl: string;
  defaultPhoneType: string;
  defaultPhoneNbr: string;
  defaultBillingFlag: boolean;
  defaultFlag: boolean;
  companyLocation: ContactCompanyLocation;
  communicationItems: ContactCommunicationItem[];
  types: ContactType[];
  customFields: ContactCustomField[];
  photo: ContactPhoto;
  ignoreDuplicates: boolean;
  _info: ContactInfo;
}

export interface ContactCompany {
  id: number;
  identifier: string;
  name: string;
  _info: {
    company_href: string;
    mobileGuid: string;
  };
}

export interface ContactSite {
  id: number;
  name: string;
  _info: {
    site_href: string;
    mobileGuid: string;
  };
}

export interface ContactRelationship {
  id: number;
  name: string;
  _info: {
    relationship_href: string;
  };
}

export interface ContactDepartment {
  id: number;
  name: string;
  _info: {
    department_href: string;
  };
}

export interface ContactCompanyLocation {
  id: number;
  name: string;
  _info: {
    location_href: string;
  };
}

export type CommunicationTypeEnum = "Phone" | "Fax" | "Email"; // from CW docs [web:40]

export interface ContactCommunicationItem {
  id: number;
  type: {
    id: number;
    name: string;
    _info: {
      type_href: string;
    };
  };
  value: string;
  defaultFlag: boolean;
  communicationType: CommunicationTypeEnum;
  domain?: string; // only present for email entries
}

export interface ContactType {
  id: number;
  name: string;
  _info: {
    type_href: string;
  };
}

export interface ContactCustomField {
  id: number;
  caption: string;
  type: string;
  entryMethod: string;
  numberOfDecimals: number;
  value: string | number | boolean | null;
  connectWiseId: string;
  rowNum: number;
  userDefinedFieldRecId: number;
  podId: string;
}

export interface ContactPhoto {
  id: number;
  name: string;
  _info: {
    filename: string;
    document_href: string;
    documentDownload_href: string;
  };
}

export interface ContactInfo {
  lastUpdated: string; // ISO datetime
  updatedBy: string;
  communications_href: string;
  notes_href: string;
  tracks_href: string;
  portalSecurity_href: string;
  activities_href: string;
  documents_href: string;
  configurations_href: string;
  tickets_href: string;
  opportunities_href: string;
  projects_href: string;
  image_href: string;
}
