// dto/create-order.dto.ts
import {
  IsArray,
  IsBoolean,
  IsEnum,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
  ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';
import { OrderStatus, PaymentMethod, ServiceType } from '@/entities/order.entity';
import { CreateOrderItemDto } from './create-order-item.dto';

export class CreateOrderDto {
  @IsOptional()
  @IsString()
  order_code?: string;

  @IsOptional()
  @IsBoolean()
  is_handwritten?: boolean;

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

  @IsNotEmpty()
  @IsString()
  sender_name: string;

  @IsNotEmpty()
  @IsString()
  sender_phone: string;

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

  @IsNotEmpty()
  @IsString()
  sender_address: string;

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

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

  // Receiver information
  @IsNotEmpty()
  @IsString()
  receiver_name: string;

  @IsNotEmpty()
  @IsString()
  receiver_phone: string;

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

  @IsNotEmpty()
  @IsString()
  receiver_address: string;

  @IsNotEmpty()
  @IsString()
  receiver_country: string;

  @IsNotEmpty()
  @IsString()
  receiver_city: string;

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

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

  // Order information
  @IsOptional()
  @IsEnum(OrderStatus)
  status?: OrderStatus;

  @IsOptional()
  @IsEnum(PaymentMethod)
  payment_method?: PaymentMethod;

  @IsOptional()
  @IsNumber()
  total_value?: number;

  @IsOptional()
  @IsNumber()
  total_weight?: number;

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

  @IsOptional()
  @IsEnum(ServiceType)
  service_type?: ServiceType;

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

  @IsOptional()
  @IsNumber()
  cod_amount?: number;

  @IsArray()
  @ValidateNested({ each: true })
  @Type(() => CreateOrderItemDto)
  items: CreateOrderItemDto[];
}