import { ApiProperty } from '@nestjs/swagger';
import { Department } from '../../../database/models/department.model';

export class DepartmentResponseDto {
  @ApiProperty({
    description: 'Unique identifier for the department',
    example: '550e8400-e29b-41d4-a716-446655440000',
  })
  id: string;

  @ApiProperty({
    description: 'Department code',
    example: 'DEPT_001',
  })
  code: string;

  @ApiProperty({
    description: 'Department name',
    example: 'Finance Department',
  })
  name: string;

  @ApiProperty({
    description: 'Blockchain wallet address',
    example: '0x1234567890123456789012345678901234567890',
    required: false,
  })
  walletAddress?: string;

  @ApiProperty({
    description: 'Department description',
    example: 'Handles financial operations',
    required: false,
  })
  description?: string;

  @ApiProperty({
    description: 'Contact email',
    example: 'contact@department.gov.in',
    required: false,
  })
  contactEmail?: string;

  @ApiProperty({
    description: 'Contact phone number',
    example: '+91-11-XXXXXXXX',
    required: false,
  })
  contactPhone?: string;

  @ApiProperty({
    description: 'Webhook URL',
    example: 'https://api.department.gov.in/webhooks/credentials',
    required: false,
  })
  webhookUrl?: string;

  @ApiProperty({
    description: 'Whether the department is active',
    example: true,
  })
  isActive: boolean;

  @ApiProperty({
    description: 'Timestamp when the department was created',
    example: '2024-01-15T10:30:00Z',
  })
  createdAt: Date;

  @ApiProperty({
    description: 'Timestamp when the department was last updated',
    example: '2024-01-15T10:30:00Z',
  })
  updatedAt: Date;

  @ApiProperty({
    description: 'Total number of applicants in this department',
    example: 150,
  })
  totalApplicants: number;

  @ApiProperty({
    description: 'Total number of issued credentials',
    example: 145,
  })
  issuedCredentials: number;

  @ApiProperty({
    description: 'Timestamp of last webhook call',
    example: '2024-01-15T10:30:00Z',
    required: false,
  })
  lastWebhookAt?: Date;

  @ApiProperty({
    description: 'Hashed API key for the department',
    example: 'hashed_api_key_value',
    required: false,
  })
  apiKeyHash?: string;

  static fromEntity(department: Department): DepartmentResponseDto {
    const dto = new DepartmentResponseDto();
    dto.id = department.id;
    dto.code = department.code;
    dto.name = department.name;
    dto.walletAddress = (department as any).walletAddress;
    dto.description = (department as any).description;
    dto.contactEmail = (department as any).contactEmail;
    dto.contactPhone = (department as any).contactPhone;
    dto.webhookUrl = department.webhookUrl;
    dto.isActive = department.isActive;
    dto.createdAt = department.createdAt;
    dto.updatedAt = department.updatedAt;
    dto.totalApplicants = (department as any).totalApplicants;
    dto.issuedCredentials = (department as any).issuedCredentials;
    dto.lastWebhookAt = (department as any).lastWebhookAt;
    dto.apiKeyHash = department.apiKeyHash;
    return dto;
  }
}
