/**
 * @aurora-catalyst-generated
 * @source cliter/iam/account.aurora.yaml
 */
import { IamRoleFieldSchema } from '@app/iam/role';
import { IamTenantFieldSchema } from '@app/iam/tenant';
import { IamUserFieldSchema } from '@app/iam/user';
import { OAuthClientFieldSchema } from '@app/o-auth/client';
import { FieldSchema } from '@aurorajs.dev/core-back';

/**
 * Field schema for IamAccount, derived from cliter/iam/account.aurora.yaml.
 * Used by @Sanitize decorator, @Format decorator and @ApplySchema decorator.
 */
export const IamAccountFieldSchema: FieldSchema[] = [
  {
    name: 'id',
    type: 'id',
    nullable: false,
    maxLength: 36,
  },
  {
    name: 'type',
    type: 'enum',
    nullable: false,
    enumOptions: ['USER', 'SERVICE'],
  },
  {
    name: 'code',
    type: 'varchar',
    nullable: true,
    maxLength: 64,
  },
  {
    name: 'email',
    type: 'varchar',
    nullable: true,
    maxLength: 128,
  },
  {
    name: 'username',
    type: 'varchar',
    nullable: false,
    maxLength: 128,
    rules: { minLength: 1 },
  },
  {
    name: 'isActive',
    type: 'boolean',
    nullable: false,
  },
  {
    name: 'clientId',
    type: 'id',
    nullable: false,
    maxLength: 36,
  },
  {
    name: 'client',
    type: 'relation',
    cardinality: 'one',
    target: () => OAuthClientFieldSchema,
  },
  {
    name: 'tags',
    type: 'array',
    nullable: true,
  },
  {
    name: 'scopes',
    type: 'array',
    nullable: true,
  },
  {
    name: 'dApplicationCodes',
    type: 'array',
    nullable: false,
  },
  {
    name: 'dPermissions',
    type: 'jsonb',
    nullable: false,
  },
  {
    name: 'dTenants',
    type: 'array',
    nullable: false,
  },
  {
    name: 'meta',
    type: 'jsonb',
    nullable: true,
  },
  {
    name: 'roles',
    type: 'relation',
    cardinality: 'many',
    target: () => IamRoleFieldSchema,
  },
  {
    name: 'tenants',
    type: 'relation',
    cardinality: 'many',
    target: () => IamTenantFieldSchema,
  },
  {
    name: 'user',
    type: 'relation',
    cardinality: 'one',
    target: () => IamUserFieldSchema,
  },
  {
    name: 'createdAt',
    type: 'timestamp',
    nullable: true,
  },
  {
    name: 'updatedAt',
    type: 'timestamp',
    nullable: true,
  },
  {
    name: 'deletedAt',
    type: 'timestamp',
    nullable: true,
  },
];
