import { BaseEntity } from '@edr/api-common';
import { Column, Entity, Index, ManyToOne, JoinColumn, Unique } from 'typeorm';
import { Company } from './company.entity';

export enum FFClientRelationship {
  ManagedAccount = 'managed_account',
  SubAgent = 'sub_agent',
}

@Entity({ schema: 'freight', name: 'ff_clients' })
@Unique(['forwarderCompanyId', 'clientCompanyId'])
@Index(['forwarderCompanyId'])
@Index(['clientCompanyId'])
export class FFClient extends BaseEntity {
  @Column({ name: 'forwarder_company_id', type: 'uuid' })
  forwarderCompanyId!: string;

  @ManyToOne(() => Company)
  @JoinColumn({ name: 'forwarder_company_id' })
  forwarderCompany!: Company;

  @Column({ name: 'client_company_id', type: 'uuid' })
  clientCompanyId!: string;

  @ManyToOne(() => Company)
  @JoinColumn({ name: 'client_company_id' })
  clientCompany!: Company;

  @Column({ name: 'relationship_type', type: 'varchar', length: 32, default: FFClientRelationship.ManagedAccount })
  relationshipType!: FFClientRelationship;

  @Column({ name: 'can_book_on_behalf', type: 'boolean', default: true })
  canBookOnBehalf!: boolean;

  @Column({ name: 'can_view_documents', type: 'boolean', default: true })
  canViewDocuments!: boolean;
}
