import { ApiProperty } from '@nestjs/swagger';

/**
 * 通用响应结果 DTO
 */
export class Result<T = any> {
  /** 状态码 */
  @ApiProperty({ description: '状态码', example: 200 })
  code!: number;

  /** 返回的数据 */
  @ApiProperty({ description: '数据', nullable: true })
  data!: T | null;

  /** 提示消息 */
  @ApiProperty({ description: '消息', example: 'success' })
  msg!: string;
}

/**
 * 成功响应结果
 */
export class OkResult<T = any> extends Result<T> {
  constructor(data: T, msg?: string, code?: number) {
    super();
    this.code = code ?? 200;
    this.data = data;
    this.msg = msg ?? 'success';
  }
}

/**
 * 失败响应结果
 */
export class FailResult<T = any> extends Result<T> {
  constructor(msg?: string, data?: T, code?: number) {
    super();
    this.code = code ?? 500;
    this.data = data ?? null;
    this.msg = msg ?? 'error';
  }
}
