import {
  IsString,
  IsNotEmpty,
  IsOptional,
  IsInt,
  IsDateString,
  Matches,
  Min,
  Max,
} from 'class-validator';

export class TenantQueryDto {
  @IsOptional()
  @IsInt()
  @Min(1)
  page?: number = 1;

  @IsOptional()
  @IsInt()
  @Min(1)
  @Max(100)
  pageSize?: number = 10;

  @IsOptional()
  @IsString()
  keyword?: string;

  @IsOptional()
  @IsString()
  status?: string;

  @IsOptional()
  @IsString()
  packageType?: string;
}

export class CreateTenantDto {
  @IsString()
  @IsNotEmpty({ message: '学校名称不能为空' })
  name: string;

  @IsString()
  @IsNotEmpty({ message: '登录账号不能为空' })
  @Matches(/^[a-zA-Z][a-zA-Z0-9_]{3,19}$/, {
    message: '登录账号必须以字母开头，4-20位字母、数字或下划线',
  })
  loginAccount: string;

  @IsOptional()
  @IsString()
  @Matches(/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{6,20}$/, {
    message: '密码至少6位，需包含字母和数字',
  })
  password?: string;

  @IsOptional()
  @IsString()
  address?: string;

  @IsOptional()
  @IsString()
  contactPerson?: string;

  @IsOptional()
  @IsString()
  @Matches(/^1[3-9]\d{9}$/, { message: '请输入正确的手机号' })
  contactPhone?: string;

  @IsOptional()
  @IsString()
  packageType?: string = 'STANDARD';

  @IsOptional()
  @IsInt()
  @Min(1)
  teacherQuota?: number = 20;

  @IsOptional()
  @IsInt()
  @Min(1)
  studentQuota?: number = 200;

  @IsOptional()
  @IsDateString()
  startDate?: string;

  @IsOptional()
  @IsDateString()
  expireDate?: string;
}

export class UpdateTenantDto {
  @IsOptional()
  @IsString()
  @IsNotEmpty({ message: '学校名称不能为空' })
  name?: string;

  @IsOptional()
  @IsString()
  address?: string;

  @IsOptional()
  @IsString()
  contactPerson?: string;

  @IsOptional()
  @IsString()
  @Matches(/^1[3-9]\d{9}$/, { message: '请输入正确的手机号' })
  contactPhone?: string;

  @IsOptional()
  @IsString()
  packageType?: string;

  @IsOptional()
  @IsInt()
  @Min(1)
  teacherQuota?: number;

  @IsOptional()
  @IsInt()
  @Min(1)
  studentQuota?: number;

  @IsOptional()
  @IsDateString()
  startDate?: string;

  @IsOptional()
  @IsDateString()
  expireDate?: string;

  @IsOptional()
  @IsString()
  status?: string;
}

export class UpdateTenantQuotaDto {
  @IsOptional()
  @IsString()
  packageType?: string;

  @IsOptional()
  @IsInt()
  @Min(1)
  teacherQuota?: number;

  @IsOptional()
  @IsInt()
  @Min(1)
  studentQuota?: number;
}

export class UpdateTenantStatusDto {
  @IsString()
  @IsNotEmpty({ message: '状态不能为空' })
  status: string;
}
