/**
 * System Setting Entity
 * Global system configuration settings across all tenants
 * Compatible with erp-core system-setting.entity
 *
 * @module Settings
 */

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

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

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

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

  @Column({
    name: 'data_type',
    type: 'varchar',
    length: 20,
    default: 'string',
  })
  dataType: 'string' | 'number' | 'boolean' | 'json' | 'array' | 'secret';

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

  @Column({ name: 'description', type: 'text', nullable: true })
  description: string | null;

  @Column({ name: 'is_public', type: 'boolean', default: false })
  isPublic: boolean;

  @Column({ name: 'is_editable', type: 'boolean', default: true })
  isEditable: boolean;

  @Column({ name: 'default_value', type: 'jsonb', nullable: true })
  defaultValue: any;

  @Column({ name: 'validation_rules', type: 'jsonb', default: '{}' })
  validationRules: Record<string, any>;

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

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

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