/**
 * ProfileTool Entity
 * Tool/permission assignments per profile
 * Compatible with erp-core profile-tool.entity
 *
 * @module Profiles
 */

import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  Index,
  ManyToOne,
  JoinColumn,
  Unique,
} from 'typeorm';
import { UserProfile } from './user-profile.entity';

@Entity({ name: 'profile_tools', schema: 'auth' })
@Unique(['profileId', 'toolCode'])
export class ProfileTool {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Index()
  @Column({ name: 'profile_id', type: 'uuid' })
  profileId: string;

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

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

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

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

  @Column({ name: 'is_mobile_only', type: 'boolean', default: false })
  isMobileOnly: boolean;

  @Column({ name: 'is_web_only', type: 'boolean', default: false })
  isWebOnly: boolean;

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

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

  @Column({ name: 'sort_order', type: 'integer', default: 0 })
  sortOrder: number;

  @Column({ name: 'is_active', type: 'boolean', default: true })
  isActive: boolean;

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

  @ManyToOne(() => UserProfile, (profile) => profile.tools, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'profile_id' })
  profile: UserProfile;
}
