import { IsString, IsEmail, IsOptional, IsMobilePhone, MinLength, MaxLength, IsNumber, IsInt, IsDateString } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';

export class CreateMemberDto {
  @ApiProperty({ description: '站点ID', example: 0 })
  @IsOptional()
  @IsInt()
  site_id?: number;

  @ApiProperty({ description: '用户名', example: 'testuser' })
  @IsString()
  @MinLength(3)
  @MaxLength(20)
  username: string;

  @ApiProperty({ description: '密码', example: '123456' })
  @IsString()
  @MinLength(6)
  @MaxLength(20)
  password: string;

  @ApiProperty({ description: '手机号', example: '13800138000' })
  @IsMobilePhone('zh-CN')
  mobile: string;

  @ApiProperty({ description: '邮箱', example: 'test@example.com', required: false })
  @IsOptional()
  @IsEmail()
  email?: string;

  @ApiProperty({ description: '昵称', example: '测试用户', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(50)
  nickname?: string;

  @ApiProperty({ description: '真实姓名', example: '张三', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(100)
  real_name?: string;

  @ApiProperty({ description: '性别', example: 1, required: false })
  @IsOptional()
  @IsInt()
  sex?: number;

  @ApiProperty({ description: '等级ID', example: 1, required: false })
  @IsOptional()
  @IsInt()
  level_id?: number;

  @ApiProperty({ description: '状态', example: 1, required: false })
  @IsOptional()
  @IsInt()
  status?: number;
}

export class UpdateMemberDto {
  @ApiProperty({ description: '昵称', example: '新昵称', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(50)
  nickname?: string;

  @ApiProperty({ description: '手机号', example: '13800138000', required: false })
  @IsOptional()
  @IsMobilePhone('zh-CN')
  mobile?: string;

  @ApiProperty({ description: '邮箱', example: 'new@example.com', required: false })
  @IsOptional()
  @IsEmail()
  email?: string;

  @ApiProperty({ description: '真实姓名', example: '李四', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(100)
  real_name?: string;

  @ApiProperty({ description: '性别', example: 1, required: false })
  @IsOptional()
  @IsInt()
  sex?: number;

  @ApiProperty({ description: '生日', example: '1990-01-01', required: false })
  @IsOptional()
  @IsDateString()
  birthday?: string;

  @ApiProperty({ description: '身份证号', example: '110101199001011234', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(18)
  id_card?: string;

  @ApiProperty({ description: '等级ID', example: 1, required: false })
  @IsOptional()
  @IsInt()
  level_id?: number;

  @ApiProperty({ description: '状态', example: 1, required: false })
  @IsOptional()
  @IsInt()
  status?: number;

  @ApiProperty({ description: '备注', example: '备注信息', required: false })
  @IsOptional()
  @IsString()
  @MaxLength(255)
  remark?: string;
}

export class QueryMemberDto {
  @ApiProperty({ description: '页码', example: 1, required: false })
  @IsOptional()
  @IsInt()
  page?: number;

  @ApiProperty({ description: '每页数量', example: 20, required: false })
  @IsOptional()
  @IsInt()
  limit?: number;

  @ApiProperty({ description: '关键词搜索', example: 'test', required: false })
  @IsOptional()
  @IsString()
  keyword?: string;

  @ApiProperty({ description: '状态筛选', example: 1, required: false })
  @IsOptional()
  @IsInt()
  status?: number;

  @ApiProperty({ description: '等级ID筛选', example: 1, required: false })
  @IsOptional()
  @IsInt()
  level_id?: number;

  @ApiProperty({ description: '开始日期', example: '2024-01-01', required: false })
  @IsOptional()
  @IsDateString()
  start_date?: string;

  @ApiProperty({ description: '结束日期', example: '2024-12-31', required: false })
  @IsOptional()
  @IsDateString()
  end_date?: string;

  @ApiProperty({ description: '站点ID', example: 0, required: false })
  @IsOptional()
  @IsInt()
  site_id?: number;
}

export class BatchUpdateStatusDto {
  @ApiProperty({ description: '会员ID数组', example: [1, 2, 3] })
  @IsNumber({}, { each: true })
  member_ids: number[];

  @ApiProperty({ description: '状态', example: 1 })
  @IsInt()
  status: number;
}

export class BatchAssignLevelDto {
  @ApiProperty({ description: '会员ID数组', example: [1, 2, 3] })
  @IsNumber({}, { each: true })
  member_ids: number[];

  @ApiProperty({ description: '等级ID', example: 1 })
  @IsInt()
  level_id: number;
}

export class AdjustPointsDto {
  @ApiProperty({ description: '会员ID', example: 1 })
  @IsInt()
  member_id: number;

  @ApiProperty({ description: '积分调整数量', example: 100 })
  @IsInt()
  points: number;

  @ApiProperty({ description: '调整原因', example: '活动奖励' })
  @IsString()
  reason: string;
}

export class AdjustBalanceDto {
  @ApiProperty({ description: '会员ID', example: 1 })
  @IsInt()
  member_id: number;

  @ApiProperty({ description: '余额调整数量', example: 50.00 })
  @IsNumber()
  amount: number;

  @ApiProperty({ description: '调整原因', example: '充值' })
  @IsString()
  reason: string;
}

export class ResetPasswordDto {
  @ApiProperty({ description: '会员ID', example: 1 })
  @IsInt()
  member_id: number;

  @ApiProperty({ description: '新密码', example: '654321' })
  @IsString()
  @MinLength(6)
  @MaxLength(20)
  new_password: string;
} 