/**
 * set-address.dto.ts
 * DTO para asignar la colonia del domicilio del usuario.
 */

export interface SetAddressDto {
  colonia: string;
  street?: string;
}

export class SetAddressDtoValidator {
  static validate(data: unknown): SetAddressDto {
    if (typeof data !== "object" || data === null) {
      throw new Error("Invalid address payload");
    }
    const obj = data as Record<string, unknown>;

    if (typeof obj.colonia !== "string" || obj.colonia.trim().length === 0) {
      throw new Error("colonia is required");
    }

    const result: SetAddressDto = { colonia: obj.colonia.trim() };
    if (typeof obj.street === "string" && obj.street.trim().length > 0) {
      result.street = obj.street.trim();
    }
    return result;
  }
}
