import { Type } from 'class-transformer';
import {
  IsIn,
  IsInt,
  IsOptional,
  IsString,
  Max,
  MaxLength,
  Min,
  ValidateIf,
} from 'class-validator';
import { RoleEnum } from '../../roles/roles.enum';
import { StatusEnum } from '../../statuses/statuses.enum';

export class AdminUserProfileDto {
  @ValidateIf((_, value) => value !== undefined)
  @IsString()
  @MaxLength(255)
  firstName?: string;

  @ValidateIf((_, value) => value !== undefined)
  @IsString()
  @MaxLength(255)
  lastName?: string;
}

export class AdminUserRoleDto {
  @IsInt()
  @IsIn([RoleEnum.admin, RoleEnum.user])
  role: RoleEnum;
}

export class AdminUserStatusDto {
  @IsInt()
  @IsIn([StatusEnum.active, StatusEnum.inactive])
  status: StatusEnum;
}

export type AdminPlayerAssignmentFilter = 'all' | 'assigned' | 'unassigned';

export class AdminPlayerQueryDto {
  @IsOptional()
  @IsString()
  search?: string;

  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  teamId?: number;

  @IsOptional()
  @IsIn(['all', 'assigned', 'unassigned'])
  assignment: AdminPlayerAssignmentFilter = 'all';

  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  page = 1;

  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  @Max(50)
  limit = 20;
}
