import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { SystemMaintenanceEntity } from '../../../domain/entities/system-maintenance.entity';

/**
 * 系统维护公告响应
 */
export class MaintenanceResponseDto {
  @ApiProperty({ description: 'ID' })
  id: string;

  @ApiProperty({ description: '维护标题' })
  title: string;

  @ApiProperty({ description: '维护说明' })
  message: string;

  @ApiProperty({ description: '维护开始时间' })
  startTime: Date;

  @ApiProperty({ description: '维护结束时间' })
  endTime: Date;

  @ApiProperty({ description: '是否激活' })
  isActive: boolean;

  @ApiProperty({ description: '是否在维护时间窗口内' })
  isInMaintenanceWindow: boolean;

  @ApiProperty({ description: '创建时间' })
  createdAt: Date;

  @ApiProperty({ description: '更新时间' })
  updatedAt: Date;

  @ApiProperty({ description: '创建人' })
  createdBy: string;

  @ApiPropertyOptional({ description: '更新人' })
  updatedBy?: string;

  static fromEntity(entity: SystemMaintenanceEntity): MaintenanceResponseDto {
    return {
      id: entity.id,
      title: entity.title,
      message: entity.message,
      startTime: entity.startTime,
      endTime: entity.endTime,
      isActive: entity.isActive,
      isInMaintenanceWindow: entity.isInMaintenanceWindow(),
      createdAt: entity.createdAt,
      updatedAt: entity.updatedAt,
      createdBy: entity.createdBy,
      updatedBy: entity.updatedBy ?? undefined,
    };
  }
}

/**
 * 维护公告列表响应
 */
export class MaintenanceListResponseDto {
  @ApiProperty({ description: '维护公告列表', type: [MaintenanceResponseDto] })
  items: MaintenanceResponseDto[];

  @ApiProperty({ description: '总数' })
  total: number;
}

/**
 * 维护详情（嵌套在状态响应中）
 */
export class MaintenanceDetailDto {
  @ApiProperty({ description: '维护标题' })
  title: string;

  @ApiProperty({ description: '维护说明' })
  message: string;

  @ApiProperty({ description: '开始时间' })
  startTime: Date;

  @ApiProperty({ description: '预计结束时间' })
  endTime: Date;

  @ApiProperty({ description: '预计剩余分钟数' })
  remainingMinutes: number;
}

/**
 * 维护状态响应（给移动端，无需登录）
 */
export class MaintenanceStatusResponseDto {
  @ApiProperty({ description: '是否在维护中' })
  isUnderMaintenance: boolean;

  @ApiPropertyOptional({ description: '维护详情', type: MaintenanceDetailDto })
  maintenance?: MaintenanceDetailDto | null;
}
