/**
 * Tenant Setting Entity
 * Custom configuration per tenant, overrides system and plan defaults
 * Hierarchy: system_settings < plan_settings < tenant_settings
 * Compatible with erp-core tenant-setting.entity
 *
 * @module Settings
 */

import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  Index,
  Unique,
} from 'typeorm';

@Entity({ name: 'tenant_settings', schema: 'core_settings' })
@Unique(['tenantId', 'key'])
export class TenantSetting {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index()
  @Column({ name: 'tenant_id', type: 'uuid' })
  tenantId: string;

  @Index()
  @Column({ name: 'key', type: 'varchar', length: 100 })
  key: string;

  @Column({ name: 'value', type: 'jsonb' })
  value: any;

  @Column({
    name: 'inherited_from',
    type: 'varchar',
    length: 20,
    default: 'custom',
  })
  inheritedFrom: 'system' | 'plan' | 'custom';

  @Column({ name: 'is_overridden', type: 'boolean', default: true })
  isOverridden: boolean;

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

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