import { ApiProperty } from '@nestjs/swagger';
import { Exclude } from 'class-transformer';
import {
  IsEmail,
  IsNumber,
  IsString,
  Length,
  ValidateIf,
} from 'class-validator';
import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
import { UserRole } from 'src/modules/user-related/user/constants';
import { UserEntity } from 'src/modules/user-related/user/domain/entities/user.entity';

export class UpdateTenantDto extends BaseStatusDto implements UserEntity {
  @ApiProperty({ name: 'name', required: true, example: 'Tenant 1' })
  @IsString()
  name: string;

  @ApiProperty({ name: 'username', required: true, example: 'tenant1' })
  @IsString()
  username: string;

  @ApiProperty({ name: 'share_margin', required: true, example: 85 })
  @IsNumber()
  share_margin: number;

  @ApiProperty({ name: 'email', required: false, example: 'tenant@mail.com' })
  @IsEmail({ ignore_max_length: true })
  @ValidateIf((body) => body.email)
  email: string;

  @Exclude()
  password: string;

  @Exclude()
  role: UserRole;
}
