/**
 * Partner Contact Entity
 * Contactos asociados a un partner
 *
 * @module Partners
 * @table partners.partner_contacts
 */

import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  Index,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { Partner } from './partner.entity';

@Entity({ name: 'partner_contacts', schema: 'partners' })
export class PartnerContact {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index()
  @Column({ name: 'partner_id', type: 'uuid' })
  partnerId: string;

  @ManyToOne(() => Partner, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'partner_id' })
  partner: Partner;

  // Datos del contacto
  @Column({ name: 'full_name', type: 'varchar', length: 200 })
  fullName: string;

  @Column({ type: 'varchar', length: 100, nullable: true })
  position: string;

  @Column({ type: 'varchar', length: 100, nullable: true })
  department: string;

  // Contacto
  @Column({ type: 'varchar', length: 255, nullable: true })
  email: string;

  @Column({ type: 'varchar', length: 30, nullable: true })
  phone: string;

  @Column({ type: 'varchar', length: 30, nullable: true })
  mobile: string;

  @Column({ type: 'varchar', length: 30, nullable: true })
  extension: string;

  // Flags
  @Column({ name: 'is_primary', type: 'boolean', default: false })
  isPrimary: boolean;

  @Column({ name: 'is_billing_contact', type: 'boolean', default: false })
  isBillingContact: boolean;

  @Column({ name: 'is_shipping_contact', type: 'boolean', default: false })
  isShippingContact: boolean;

  @Column({ name: 'receives_notifications', type: 'boolean', default: true })
  receivesNotifications: boolean;

  // Notas
  @Column({ type: 'text', nullable: true })
  notes: string;

  // Metadata
  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at', type: 'timestamptz' })
  updatedAt: Date;
}
