import {
  Entity,
  Column,
  OneToOne,
  ManyToOne,
  JoinColumn,
} from 'typeorm';
import { BaseEntity } from '../database/base.entity';
import { TenantEntity } from './tenant.entity';
import { CurrencyEntity } from './currency.entity';

/**
 * TenantSettings — per-tenant company configuration.
 *
 * Sections:
 * - Company Details (name, currency, timezone, fiscal year, website, logo)
 * - Branding (primary/secondary colors)
 * - Contact & Tax (address, phone, email, tax/GST/PAN)
 * - Bank Details (bank name, account, IFSC)
 * - Lead Distribution (distribution mode)
 * - Default Terms & Conditions
 */
@Entity('tenant_settings')
export class TenantSettingsEntity extends BaseEntity {
  // --- Company Details ---
  @Column({ type: 'varchar', length: 255, nullable: true })
  company_name: string | null;

  @ManyToOne(() => CurrencyEntity)
  @JoinColumn({ name: 'default_currency_id' })
  default_currency: CurrencyEntity;

  @Column({ type: 'uuid', nullable: true })
  default_currency_id: string | null;

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

  @Column({ type: 'varchar', length: 20, nullable: true })
  fiscal_year_start: string | null;

  @Column({ type: 'varchar', length: 500, nullable: true })
  website_url: string | null;

  @Column({ type: 'varchar', length: 500, nullable: true })
  logo_url: string | null;

  // --- Branding ---
  @Column({ type: 'varchar', length: 20, default: '#10b981' })
  primary_color: string;

  @Column({ type: 'varchar', length: 20, default: '#1e293b' })
  secondary_color: string;

  // --- Contact & Tax ---
  @Column({ type: 'text', nullable: true })
  address: string | null;

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

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

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

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

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

  // --- Bank Details ---
  @Column({ type: 'varchar', length: 255, nullable: true })
  bank_name: string | null;

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

  @Column({ type: 'varchar', length: 50, nullable: true })
  ifsc_code: string | null;

  // --- Lead Distribution ---
  @Column({ type: 'varchar', length: 50, default: 'round_robin' })
  distribution_mode: string;

  // --- Default Terms & Conditions ---
  @Column({ type: 'text', nullable: true })
  terms_and_conditions: string | null;
}
